Skip to content
Back to search

mcp-http-interfaces

HTTP Interfaces in an MCP Server

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/praveen110195--mcp-http-interfaces/badge.svg)](/listings/praveen110195--mcp-http-interfaces)

HTML

<a href="/listings/praveen110195--mcp-http-interfaces"><img src="/api/listings/praveen110195--mcp-http-interfaces/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 92 lines
  1. # HTTP Interfaces in an MCP Server
  2. Can you use Spring HTTP interfaces inside an MCP server? Yes. This repo has two Spring Boot apps. One is a small todos REST API. The other is a Spring AI MCP server that calls that API through a declarative HTTP interface (`@HttpExchange`), so the MCP tools never touch `RestClient` directly.
  3. ## Tested with
  4. Java 25, Spring Boot 4.1.2, Spring AI 2.0.2. Built and run on JDK 27.
  5. ## What you need
  6. - JDK 25 or newer
  7. - No API keys. The MCP server does not call a model. Your MCP client brings its own.
  8. ## Run it
  9. This is a multi-module Maven project. Start the API first, then the MCP server, each in its own terminal.
  10. ```bash
  11. ./mvnw -pl todos-api spring-boot:run
  12. ```
  13. ```bash
  14. ./mvnw -pl todos-mcp-server spring-boot:run
  15. ```
  16. | App | Port | What it is |
  17. |-----|------|------------|
  18. | `todos-api` | 8080 | REST API at `/api/todos`, seeded with 5 todos (in memory, reset on restart) |
  19. | `todos-mcp-server` | 8081 | MCP server over Streamable HTTP at `/mcp` |
  20. ## Try it
  21. Check the API:
  22. ```bash
  23. curl localhost:8080/api/todos
  24. ```
  25. Connect any MCP client to `http://localhost:8081/mcp`. For Claude Code:
  26. ```bash
  27. claude mcp add --transport http todos-demo http://localhost:8081/mcp
  28. ```
  29. The server exposes 5 tools:
  30. | Tool | HTTP call it makes |
  31. |------|--------------------|
  32. | `list_todos` | `GET /api/todos` |
  33. | `get_todo` | `GET /api/todos/{id}` |
  34. | `create_todo` | `POST /api/todos` |
  35. | `complete_todo` | `GET` then `PUT /api/todos/{id}` |
  36. | `delete_todo` | `DELETE /api/todos/{id}` |
  37. Then ask your client something like this:
  38. ```text
  39. What's on my todo list? Mark "Answer the HTTP interfaces question" as done and add a todo to record the follow-up video.
  40. ```
  41. Run `curl localhost:8080/api/todos` again and you'll see the changes in the API.
  42. ## Where to look
  43. - [TodoClient.java](todos-mcp-server/src/main/java/dev/danvega/todos/mcp/TodoClient.java) is the HTTP interface. Spring creates the implementation.
  44. - [HttpClientConfig.java](todos-mcp-server/src/main/java/dev/danvega/todos/mcp/HttpClientConfig.java) registers it with `@ImportHttpServices` in a group named `todos`. It also turns a 404 into a clear message for the model.
  45. - [TodoTools.java](todos-mcp-server/src/main/java/dev/danvega/todos/mcp/TodoTools.java) has the `@McpTool` methods. Each one calls `TodoClient`.
  46. The base URL lives in [application.yaml](todos-mcp-server/src/main/resources/application.yaml):
  47. ```yaml
  48. spring:
  49. http:
  50. serviceclient:
  51. todos:
  52. base-url: http://localhost:8080
  53. ```
  54. ## Branches
  55. | Branch | What it has |
  56. |--------|-------------|
  57. | `start` | The finished todos API and an MCP server with no tools. Start here to build it yourself. |
  58. | `main` | The finished code: the HTTP interface, the MCP tools, the 404 handling and the tests. |
  59. ## Good to know
  60. - Spring Boot 4 auto-configures HTTP service groups, but only with a client starter on the classpath. The MCP server adds `spring-boot-starter-restclient` for that.
  61. - Because `TodoClient` is an interface, [TodoToolsTest](todos-mcp-server/src/test/java/dev/danvega/todos/mcp/TodoToolsTest.java) tests the tools with a plain fake. No HTTP and no running API.
  62. - The MCP server has its own `Todo` record. The two apps share no code, only the JSON shape.
  63. - In Spring AI 2.0 the MCP annotations live in `org.springframework.ai.mcp.annotation`. Older examples use `org.springaicommunity.mcp.annotation`.
  64. - When a tool fails, Spring AI prints the error message twice in the tool result. That comes from Spring AI, not this code.

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.