{"id":26538590,"url":"https://github.com/oalles/spring-ai-mcp-test","last_synced_at":"2026-04-10T01:02:43.836Z","repository":{"id":283107718,"uuid":"950708694","full_name":"oalles/spring-ai-mcp-test","owner":"oalles","description":"Showcases how to integrate Spring AI's support for MCP (Model Context Protocol) within Spring Boot applications, covering both server-side and client-side implementations.","archived":false,"fork":false,"pushed_at":"2025-03-18T15:16:28.000Z","size":555,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-18T16:30:25.709Z","etag":null,"topics":["mcp","mcp-client","mcp-server","spring","spring-ai","spring-ai-ollama","springboot"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oalles.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-18T15:12:35.000Z","updated_at":"2025-03-18T15:19:01.000Z","dependencies_parsed_at":"2025-03-18T16:30:35.287Z","dependency_job_id":"134b5e9d-a911-4494-b60f-8c98de7cbd2e","html_url":"https://github.com/oalles/spring-ai-mcp-test","commit_stats":null,"previous_names":["oalles/spring-ai-mcp-test"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/oalles/spring-ai-mcp-test","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oalles%2Fspring-ai-mcp-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oalles%2Fspring-ai-mcp-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oalles%2Fspring-ai-mcp-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oalles%2Fspring-ai-mcp-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oalles","download_url":"https://codeload.github.com/oalles/spring-ai-mcp-test/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oalles%2Fspring-ai-mcp-test/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261733887,"owners_count":23201745,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mcp","mcp-client","mcp-server","spring","spring-ai","spring-ai-ollama","springboot"],"created_at":"2025-03-21T23:18:49.885Z","updated_at":"2025-12-30T22:25:33.830Z","avatar_url":"https://github.com/oalles.png","language":"Java","funding_links":[],"categories":["🔌 API"],"sub_categories":[],"readme":"# MCP Host Project\n\n## Description\n\nThis project showcases how to integrate Spring AI's support for MCP (Model Context Protocol) within Spring Boot applications, \ncovering both server-side and client-side implementations.\n\n## MCP\nMCP is a standard that streamlines the management of contextual interactions in AI models, enabling consistent integration \nwith external data sources and tools. \n\n[Spring AI MCP](https://docs.spring.io/spring-ai/reference/api/mcp/mcp-overview.html) extends the [MCP Java SDK](https://github.com/modelcontextprotocol/java-sdk) \nand provides dedicated Spring Boot starters for both clients and servers. \n\nThe MCP client handles communication and connection management with MCP servers. \n\nIn this project, we leverage Spring AI to build MCP servers, making their capabilities available to LLMs. \nNote that the use of a model supporting TOOLS is required; we are using `Llama3.2` via `Ollama`.\n\n## Modules\n\nThis project consists of three main modules:\n\n### Geocoder Service\n\n- **Port**: 8081\n- **Description**: Provides latitude and longitude for a given city.\n- [configuration](geocoder/src/main/resources/application.yml)\n\n```java\npublic interface Geocoder {\n    GeoCodeResult geocode(String city) throws Exception;\n}\n\npublic record GeoCodeResult(double latitude, double longitude) {}\n```\n\n### Timezone Service\n\n- **Port**: 8082\n- **Description**: Provides timezone information for a given latitude and longitude.\n- [configuration](timezone/src/main/resources/application.yml)\n\n```java\npublic interface TimeZoneService {\n    Optional\u003cTimeZone\u003e getTimeZoneFromLocation(double latitude, double longitude) throws Exception;\n}\npublic record TimeZone(\n        String id,\n        String name,\n        int rawOffset,\n        int dstSavings\n) {}\n```\n\n### MCP Host\n\n- **Description**: Uses the Geocoder and Timezone services via MCP clients and provides a console interface to interact with an LLM.\n- [configuration](mcp-host/src/main/resources/application.yml)\n\n```java\n@Bean\nCommandLineRunner runner(final ChatClient.Builder chatClientBuilder, List\u003cToolCallback\u003e toolCallbacks) {\n\n   final ChatClient agent = chatClientBuilder.build();\n\n   return args -\u003e {\n      try (Scanner scanner = new Scanner(System.in)) {\n         while (true) {\n            System.out.print(\"\\n\\nEnter city (or type 'exit' to quit): \");\n            String city = scanner.nextLine();\n            if (\"exit\".equalsIgnoreCase(city)) {\n               break;\n            }\n\n            String queryTemplate = \"\"\"\n                    Please use the available tools to find the latitude and longitude for the city `{city}`. Once you have this information, \n                    use the tools to determine and provide all the timezone details for that location in the same language.\n                    \"\"\";\n\n            String systemTemplate = \"\"\"\n                    You are an AI assistant specialized in providing geographical information. Your task is to use the provided tools to gather and deliver accurate data.\n                    \"\"\";\n\n            String llmResponse = agent\n                    .prompt()\n                    .advisors(new SimpleLoggerAdvisor())\n                    .system(systemSpec -\u003e systemSpec.text(systemTemplate))\n                    .user(userSpec -\u003e userSpec.text(queryTemplate).param(\"city\", city))\n                    .tools(toolCallbacks)\n                    .call()\n                    .content();\n\n            log.info(\"\\n\\n{}\", llmResponse);\n         }\n      }\n   };\n}\n```\n\n## Running the Project\n\n1. **Start Geocoder Service**:\n    ```bash\n    cd geocoder\n    mvn spring-boot:run\n    ```\n\n2. **Start Timezone Service**:\n    ```bash\n    cd timezone\n    mvn spring-boot:run\n    ```\n\n3. **Start MCP Host**:\n    ```bash\n    cd mcp-host\n    mvn spring-boot:run\n    ```\n\n## Usage\n\n1. **Interact with MCP Host**:\n    - Run the MCP Host application.\n    - Enter city names in the console.\n    - The system will provide latitude, longitude, and timezone information for the entered city.\n\nInsertamos image\n\n![image](./mcp.gif)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foalles%2Fspring-ai-mcp-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foalles%2Fspring-ai-mcp-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foalles%2Fspring-ai-mcp-test/lists"}