Skip to content

MCP Server

MCP (Model Context Protocol) server module for Atmosphere. Exposes annotation-driven tools, resources, and prompt templates to AI agents over Streamable HTTP, WebSocket, or SSE transport.

<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-mcp</artifactId>
<version>LATEST</version> <!-- check Maven Central for latest -->
</dependency>
@McpServer(name = "my-server", path = "/atmosphere/mcp")
public class MyMcpServer {
@McpTool(name = "greet", description = "Say hello")
public String greet(@McpParam(name = "name", required = true) String name) {
return "Hello, " + name + "!";
}
@McpResource(uri = "atmosphere://server/status",
name = "Server Status",
description = "Current server status")
public String serverStatus() {
return "OK";
}
@McpPrompt(name = "summarize", description = "Summarize a topic")
public List<McpMessage> summarize(@McpParam(name = "topic") String topic) {
return List.of(
McpMessage.system("You are a summarization expert."),
McpMessage.user("Summarize: " + topic)
);
}
}
AnnotationTargetDescription
@McpServerClassMarks the class as an MCP server and sets the endpoint path
@McpToolMethodExposes a method as a callable tool (tools/call)
@McpResourceMethodExposes a method as a read-only resource (resources/read)
@McpPromptMethodExposes a method as a prompt template (prompts/get)
@McpParamParameterAnnotates parameters with name, description, and required flag
TransportHow to connect
Streamable HTTP (recommended)POST http://host:port/atmosphere/mcp
WebSocketws://host:port/atmosphere/mcp
SSEGET http://host:port/atmosphere/mcp

Agents get automatic reconnection, heartbeats, and transport fallback from Atmosphere’s transport layer.

Works with Claude Desktop, VS Code Copilot, Cursor, and any MCP-compatible agent:

{
"mcpServers": {
"my-server": { "url": "http://localhost:8080/atmosphere/mcp" }
}
}

For clients that only support stdio, build the bridge JAR with mvn package -Pstdio-bridge -DskipTests and point the client at the resulting atmosphere-mcp-*-stdio-bridge.jar.

@McpTool methods can declare framework types as parameters. These are auto-injected at invocation time and excluded from the tool’s JSON Schema:

TypeWhat’s injectedRequires
BroadcasterBroadcasterFactory.lookup(topic, true)A @McpParam(name="topic") argument
StreamingSessionBroadcasterStreamingSession wrapping the topic’s BroadcasterA @McpParam(name="topic") + atmosphere-ai
AtmosphereConfigThe framework’s AtmosphereConfigNothing
BroadcasterFactoryThe framework’s BroadcasterFactoryNothing
AtmosphereFrameworkThe framework instanceNothing
@McpTool(name = "broadcast", description = "Send a message to a chat topic")
public String broadcast(
@McpParam(name = "message") String message,
@McpParam(name = "topic") String topic,
Broadcaster broadcaster) {
broadcaster.broadcast(message);
return "sent to " + topic;
}

With atmosphere-ai on the classpath, inject a StreamingSession that wraps the topic’s Broadcaster:

@McpTool(name = "ask_ai", description = "Ask AI and stream answer to a topic")
public String askAi(
@McpParam(name = "question") String question,
@McpParam(name = "topic") String topic,
StreamingSession session) {
Thread.startVirtualThread(() -> {
var request = ChatCompletionRequest.builder(model).user(question).build();
client.streamChatCompletion(request, session);
});
return "streaming to " + topic;
}

McpTracing wraps every tools/call, resources/read, and prompts/get invocation in an OTel trace span:

AttributeDescription
mcp.tool.nameTool/resource/prompt name
mcp.tool.type"tool", "resource", or "prompt"
mcp.tool.arg_countNumber of arguments provided
mcp.tool.errortrue if invocation failed

With the Spring Boot starter, McpTracing is auto-configured when an OpenTelemetry bean is present.