TheHyperEngineer/news-mcp-server
If you are the rightful owner of news-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The MCP Tool Server for the AI News Agency is a standalone Spring Boot microservice that serves as a Tool Provider for an AI Chat Application, utilizing the Spring AI Model Context Protocol (MCP) to offer tools for AI agents.
MCP Tool Server for the AI News Agency
This project is a dedicated, standalone Spring Boot microservice that acts as a Tool Provider for our main AI Chat Application. It uses the Spring AI Model Context Protocol (MCP) to expose a set of functions (tools) that our AI agents can call to interact with the real world.
The primary responsibility of this server is to abstract away the complexities of calling external APIs, providing a clean, secure, and consistent interface for our AI agents.
Core Technology
- Spring Boot 3 & Java 17+
- Project Reactor (WebFlux): For a fully non-blocking, reactive foundation.
- Spring AI MCP Server: The core of the project, using the
spring-ai-mcp-server-webflux-spring-boot-starterto automatically expose tools over the Streamable HTTP transport. - Google Custom Search API: The external data source for our tools.
Exposed Tools
This server exposes the following tools to any connected MCP client:
| Tool Name | Description | Implementation Details |
|---|---|---|
get-latest-news | Gets the latest breaking news headlines for a specific topic. Ideal for researching current events. | Calls the Google Custom Search API with the topic, sorts by date, and streams formatted "Headline - Snippet" strings back to the agent. |
get-trending-topics | Gets a list of currently trending topics or hashtags on social media to make content relevant. | Cleverly searches Google for "trending hashtags," then uses a regular expression to parse and extract a list of hashtags from the search results. |
Setup and Configuration
To run this server, you must provide credentials for the Google Custom Search API.
1. Prerequisites
You need two credentials from the Google Cloud Platform:
- API Key: Create one in the Google Cloud Console.
- Custom Search Engine ID (CX): Create a search engine in the Programmable Search Engine control panel. Important: In the setup, enable "Search the entire web".
2. Configuration
Once you have your credentials, add them to the src/main/resources/application.properties file.
# Server Configuration
server.port=8081
spring.ai.mcp.path=/mcp
# --- Google Custom Search API Credentials ---
# Replace with your actual API Key and Search Engine ID (CX)
google.api.key=YOUR_GOOGLE_API_KEY
google.api.cx=YOUR_SEARCH_ENGINE_ID
Running the Application
You can run the server using the standard Spring Boot Maven command:
./mvnw spring-boot:run
Once running, the server will be available at http://localhost:8081 and the MCP endpoint will be active at http://localhost:8081/mcp.
Integration with the Main Chat Application
This server is the "Tool Shed" for our main chat-app (the "Factory"). The chat-app connects to this server to use its tools.
graph TD
subgraph The Factory (chat-app)
A[AI Agent]
end
subgraph The Tool Shed (mcp-server)
B(MCP Endpoint `/mcp`)
C[get-latest-news Tool]
D[get-trending-topics Tool]
end
subgraph The Real World
E[Google Search API 🌐]
end
A -- "I need to use 'get-latest-news'!" --> B;
B --> C;
C -- "Calls for data" --> E;
E -- "Returns search results" --> C;
C -- "Streams formatted headlines" --> B;
B -- "Streams results back to agent" --> A;
style A fill:#90EE90,stroke:#333,stroke-width:2px
style B fill:#87CEEB,stroke:#333,stroke-width:2px
The chat-app configures this connection in its application.properties:
# In chat-app/src/main/resources/application.properties
spring.ai.mcp.streamable.http.client.base-url=http://localhost:8081/mcp
How to Add a New Tool
The MCP framework makes adding new tools incredibly simple:
- Open the
McpServerTools.javafile. - Add a new public method that performs the desired action (e.g.,
getWeather(String location)). - Annotate the method with
@Tooland provide anameanddescription. The description is crucial, as it's what the AI agent uses to decide whether to call your tool. - Restart the server.
The new tool will be automatically discovered by the chat-app on its next startup, with no changes required on the client side