news-mcp-server

TheHyperEngineer/news-mcp-server

3.2

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.

Tools
2
Resources
0
Prompts
0

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-starter to 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 NameDescriptionImplementation Details
get-latest-newsGets 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-topicsGets 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:

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:

  1. Open the McpServerTools.java file.
  2. Add a new public method that performs the desired action (e.g., getWeather(String location)).
  3. Annotate the method with @Tool and provide a name and description. The description is crucial, as it's what the AI agent uses to decide whether to call your tool.
  4. 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