### Java MCP Client - Manual Setup Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Example of how to manually set up and use the McpClient in a Java application to interact with an MCP server. ```APIDOC ## Java MCP Client - Manual Setup ### Description This Java code demonstrates how to manually initialize and use the `McpClient` to communicate with an MCP server via stdio transport. ### Method N/A (Client Usage) ### Endpoint N/A (Client Interaction) ### Parameters N/A ### Request Example ```java import com.spring.ai.mcp.client.McpClient; import com.spring.ai.mcp.client.transport.stdio.StdioClientTransport; import com.spring.ai.mcp.client.transport.ServerParameters; import com.spring.ai.mcp.client.model.CallToolRequest; import com.spring.ai.mcp.client.model.CallToolResult; import com.spring.ai.mcp.client.model.ListToolsResult; import java.util.Map; // ... inside a method or main function ... var stdioParams = ServerParameters.builder("java") .args("-jar", "/ABSOLUTE/PATH/TO/PARENT/FOLDER/mcp-weather-stdio-server-0.0.1-SNAPSHOT.jar") .build(); var stdioTransport = new StdioClientTransport(stdioParams); var mcpClient = McpClient.sync(stdioTransport).build(); mcpClient.initialize(); ListToolsResult toolsList = mcpClient.listTools(); CallToolResult weather = mcpClient.callTool( new CallToolRequest("getWeatherForecastByLocation", Map.of("latitude", "47.6062", "longitude", "-122.3321"))); CallToolResult alert = mcpClient.callTool( new CallToolRequest("getAlerts", Map.of("state", "NY"))); mcpClient.closeGracefully(); ``` ### Response N/A ``` -------------------------------- ### Server Path Usage Examples (Bash) Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Demonstrates correct usage of server paths in command-line arguments, including relative, absolute, and Windows-specific formats. It highlights the importance of using forward slashes or escaped backslashes for Windows paths and ensuring the correct runtime is installed. ```bash # Relative path java -jar build/libs/client.jar ./server/build/libs/server.jar # Absolute path java -jar build/libs/client.jar /Users/username/projects/mcp-server/build/libs/server.jar # Windows path (either format works) java -jar build/libs/client.jar C:/projects/mcp-server/build/libs/server.jar java -jar build/libs/client.jar C:\projects\mcp-server\build\libs\server.jar ``` -------------------------------- ### Java Setup for Spring AI MCP Web Search Chatbot Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt This Java setup guide outlines the system requirements and initial steps for creating an interactive chatbot using Spring AI's MCP with the Brave Search server. It details the necessary software (Java, Maven, npx) and API keys (Anthropic, Brave Search). ```bash # Install npx (Node Package eXecute): # First, make sure to install [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) # and then run: npm install -g npx # Clone the repository: ``` -------------------------------- ### Rust MCP Server Integration Example (AgentAI) Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Demonstrates how to integrate MCP Servers within the AgentAI Rust library. This example showcases the library's capability to connect with various LLM APIs and utilize tools through MCP. ```rust use agentai::AgentBuilder; #[tokio::main] async fn main() { let agent = AgentBuilder::new() .with_llm(agentai::llms::OpenAI::new("sk-...")) .with_tool("mcp_server", agentai::tools::mcp::McpServer::new("http://localhost:8080")) .build(); let response = agent.run("What is the weather in London?").await; println!("{}", response); } ``` -------------------------------- ### MCP Server Example Prompt for Claude Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt An example prompt to guide Claude in building a custom MCP server. It specifies resource exposure, tool provision, prompt integration, and external system connections. ```plaintext Build an MCP server that: - Connects to my company's PostgreSQL database - Exposes table schemas as resources - Provides tools for running read-only SQL queries - Includes prompts for common data analysis tasks ``` -------------------------------- ### MCP Client Root Configuration Example Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt An example JSON configuration demonstrating how an MCP client might expose roots to the server. This helps in organizing and accessing different resources like local repositories or API endpoints. ```json { "roots": [ { "uri": "file:///home/user/projects/frontend", "name": "Frontend Repository" }, { "uri": "https://api.example.com/v1", "name": "API Endpoint" } ] } ``` -------------------------------- ### Apify MCP Tester Connection Example (JavaScript) Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Illustrates how the Apify MCP Tester client connects to an MCP server using Server-Sent Events (SSE). This JavaScript code snippet shows a basic connection setup. ```javascript const mcpTester = require('apify-mcp-tester'); mcpTester.connect({ url: 'http://localhost:8080', headers: { 'Authorization': 'Bearer YOUR_TOKEN' } }).then(client => { console.log('Connected to MCP server!'); client.on('message', (data) => { console.log('Received:', data); }); }).catch(err => { console.error('Connection failed:', err); }); ``` -------------------------------- ### Clone and Build Brave Chatbot Example Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Clones the Spring AI examples repository, navigates to the Brave Chatbot directory, sets necessary API keys, and builds the application using Maven. ```bash git clone https://github.com/spring-projects/spring-ai-examples.git cd model-context-protocol/brave-chatbot export ANTHROPIC_API_KEY='your-anthropic-api-key-here' export BRAVE_API_KEY='your-brave-api-key-here' ./mvnw clean install ``` -------------------------------- ### Example HTTP GET Request Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Provides an example of a complete HTTP GET request to an MCP server, including the Host header and the required Authorization header with a Bearer token. ```HTTP GET /mcp HTTP/1.1 Host: mcp.example.com Authorization: Bearer eyJhbGciOiJIUzI1NiIs... ``` -------------------------------- ### Initialize MCP Project Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Commands to create a new project directory, set up a virtual environment, and install necessary dependencies for an MCP server. ```bash uv init weather cd weather uv venv source .venv/bin/activate uv add "mcp[cli]" httpx touch weather.py ``` ```powershell uv init weather cd weather uv venv .venv\Scripts\activate uv add mcp[cli] httpx new-item weather.py ``` -------------------------------- ### Initialize MCP Project Environment Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Sets up the project directory, initializes npm, and installs required dependencies for both MacOS/Linux and Windows environments. ```bash mkdir weather cd weather npm init -y npm install @modelcontextprotocol/sdk zod npm install -D @types/node typescript mkdir src touch src/index.ts ``` ```powershell md weather cd weather npm init -y npm install @modelcontextprotocol/sdk zod npm install -D @types/node typescript md src new-item src\index.ts ``` -------------------------------- ### Initialize Kotlin MCP Server Instance Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Basic setup for a Kotlin MCP server instance, defining implementation details and server capabilities. ```kotlin fun `run mcp server`() { val server = Server( Implementation( name = "weather", version = "1.0.0" ), ServerOptions( capabilities = ServerCapabilities(tools = ServerCapabilities.Tools(listChanged = true)) ) ) } ``` -------------------------------- ### Verify Java Installation Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Checks if Java is installed and displays its version. This is a prerequisite for using Gradle and building the project. ```bash java --version ``` -------------------------------- ### Verify Node.js Installation Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Command line instruction to verify that Node.js is installed on the local system, which is a prerequisite for running the MCP server. ```bash node --version ``` -------------------------------- ### Initialize and Run MCP Server Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Initializes the MCP server instance and starts it using the standard I/O transport mechanism. ```python if __name__ == "__main__": mcp.run(transport='stdio') ``` -------------------------------- ### Initialize FastMCP Server Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Basic setup for a FastMCP server, including imports and constant definitions for the weather API. ```python from typing import Any import httpx from mcp.server.fastmcp import FastMCP mcp = FastMCP("weather") NWS_API_BASE = "https://api.weather.gov" USER_AGENT = "weather-app/1.0" ``` -------------------------------- ### Search for API Usage Examples Source: https://github.com/exa-labs/exa-mcp-server/blob/main/skills/search/references/patterns-code.md Use `web_search_exa` to find code examples for specific API calls within a given programming language. Specify the API, action, language, and desired number of results. ```shell web_search_exa { "query": "Stripe API create subscription Node.js code example", "numResults": 5 } ``` -------------------------------- ### Amazon Q CLI Installation Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Provides the command to install the Amazon Q CLI using Homebrew. This tool is an agentic coding assistant for terminals with full support for MCP servers. ```bash brew install amazon-q ``` -------------------------------- ### Configure Claude Desktop for Exa MCP (Manual) Source: https://github.com/exa-labs/exa-mcp-server/blob/main/README.md Add this JSON configuration to your `claude_desktop_config.json` for manual setup of the Exa MCP server in Claude Desktop. ```json { "mcpServers": { "exa": { "command": "npx", "args": ["-y", "mcp-remote", "https://mcp.exa.ai/mcp"] } } } ``` -------------------------------- ### Main Entry Point for MCP Client Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt The main execution logic that initializes the client, connects to the server, and starts the chat loop. ```python async def main(): if len(sys.argv) < 2: print("Usage: python client.py ") sys.exit(1) client = MCPClient() try: await client.connect_to_server(sys.argv[1]) await client.chat_loop() finally: await client.cleanup() if __name__ == "__main__": import sys asyncio.run(main()) ``` -------------------------------- ### Task Decomposition Example Source: https://github.com/exa-labs/exa-mcp-server/blob/main/skills/search/SKILL.md Illustrates how to decompose a complex query into multiple parallel sub-questions for subagents to cover different search territories. ```text 1. "What open-source LLM fine-tuning frameworks do production engineers recommend, and what do they say about using them in real deployments?" 2. "What open-source LLM fine-tuning tools have launched or gained traction in the last 6 months that aren't yet widely known?" 3. "What are the most common complaints, failure modes, and reasons teams migrated away from specific open-source LLM fine-tuning frameworks in production?" ``` -------------------------------- ### Bash Command to Run .NET Server Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Executes the .NET server application. This command starts the server and makes it ready to listen for incoming requests. ```bash dotnet run ``` -------------------------------- ### C# Project Setup (Bash) Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Provides commands to create a new .NET console project, navigate into its directory, and add necessary NuGet package dependencies for the Model Context Protocol (MCP) client and Anthropic SDK. ```bash dotnet new console -n QuickstartClient cd QuickstartClient dotnet add package ModelContextProtocol --prerelease dotnet add package Anthropic.SDK dotnet add package Microsoft.Extensions.Hosting dotnet add package Microsoft.Extensions.AI ``` -------------------------------- ### Exa Search: Company News Coverage Source: https://github.com/exa-labs/exa-mcp-server/blob/main/README.md Example for researching recent news coverage related to a company or topic. This query specifies a category and a start date for the search. ```json web_search_advanced_exa { "query": "Anthropic AI safety", "category": "news", "numResults": 15, "startPublishedDate": "2024-01-01" } ``` -------------------------------- ### Initialize MCP Client Environment Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Commands to set up a new Python project using uv, configure virtual environments, and install necessary dependencies for MCP development. ```bash uv init mcp-client cd mcp-client uv venv source .venv/bin/activate uv add mcp anthropic python-dotenv touch client.py ``` -------------------------------- ### Kotlin HttpClient Setup for Weather API Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Configures an HTTP client with base URL, default headers (Accept and User-Agent), and JSON content negotiation for interacting with the Weather.gov API. It installs the ContentNegotiation plugin for JSON serialization and deserialization, ignoring unknown keys. ```kotlin val httpClient = HttpClient { defaultRequest { url("https://api.weather.gov") headers { append("Accept", "application/geo+json") append("User-Agent", "WeatherApiClient/1.0") } contentType(ContentType.Application.Json) } // Install content negotiation plugin for JSON serialization/deserialization install(ContentNegotiation) { json(Json { ignoreUnknownKeys = true }) } } ``` -------------------------------- ### Configure Environment Variables for Server Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Example JSON configuration for a server, demonstrating how to set environment variables, including APPDATA for Windows paths. This is crucial for resolving ENOENT errors related to path expansion. ```json { "brave-search": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-brave-search"], "env": { "APPDATA": "C:\\Users\\user\\AppData\\Roaming\\", "BRAVE_API_KEY": "..." } } } ``` -------------------------------- ### Initialize MCP Client and List Tools Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Sets up the StdioClientTransport and initializes the McpClient to connect to a server. It retrieves and displays the list of available tools provided by the server. ```csharp var (command, arguments) = GetCommandAndArguments(args); var clientTransport = new StdioClientTransport(new() { Name = "Demo Server", Command = command, Arguments = arguments, }); await using var mcpClient = await McpClientFactory.CreateAsync(clientTransport); var tools = await mcpClient.ListToolsAsync(); foreach (var tool in tools) { Console.WriteLine($"Connected to server with tools: {tool.Name}"); } ``` -------------------------------- ### Error Handling Example Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Provides an example of the JSON-RPC error structure that clients should return for common failure cases. ```APIDOC ## Error Handling Example Clients are expected to return errors in a standardized format, often using a JSON-RPC-like structure, to indicate failure conditions. ### Example Error Response This example demonstrates an error where a user rejected a sampling request: ```json { "jsonrpc": "2.0", "id": 1, "error": { "code": -1, "message": "User rejected sampling request" } } ``` * **`jsonrpc`**: Specifies the JSON-RPC protocol version. * **`id`**: The identifier for the request that resulted in the error. * **`error`**: An object containing error details. * **`code`**: A numerical error code. * **`message`**: A human-readable string describing the error. ``` -------------------------------- ### Run MCP Client via Command Line Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Instructions and commands for building the project and running the MCP client against various server types. ```bash ./gradlew build java -jar build/libs/.jar path/to/server.jar ``` -------------------------------- ### Initialize Kotlin Project with Gradle Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Creates a new project directory and initializes a Kotlin application project using Gradle. This sets up the basic project structure and build files. ```bash # Create a new directory for our project mkdir kotlin-mcp-client cd kotlin-mcp-client # Initialize a new kotlin project gradle init ``` ```powershell # Create a new directory for our project md kotlin-mcp-client cd kotlin-mcp-client # Initialize a new kotlin project grade init ``` -------------------------------- ### Weather Service Tool Example Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Example of a Java service class annotated with @Service and @Tool to expose weather-related functionality as an MCP tool. ```APIDOC ## POST /api/tools/weather ### Description This endpoint allows retrieving weather forecasts and active alerts based on location or state. ### Method POST ### Endpoint /api/tools/weather ### Parameters #### Request Body - **toolName** (string) - Required - The name of the tool to call (e.g., "getWeatherForecastByLocation", "getAlerts"). - **parameters** (object) - Required - A map of parameters for the tool. - **latitude** (string) - Optional - Latitude for weather forecast. - **longitude** (string) - Optional - Longitude for weather forecast. - **state** (string) - Optional - Two-letter US state code for alerts. ### Request Example ```json { "toolName": "getWeatherForecastByLocation", "parameters": { "latitude": "47.6062", "longitude": "-122.3321" } } ``` ### Response #### Success Response (200) - **result** (string) - Description of the weather forecast or alerts. #### Response Example ```json { "result": "The weather forecast for the specified location is..." } ``` ``` -------------------------------- ### Install uv package manager Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Commands to install the uv package manager on different operating systems to manage Python environments and dependencies. ```bash curl -LsSf https://astral.sh/uv/install.sh | sh ``` ```powershell powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" ``` -------------------------------- ### Install NPM Globally Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Command to install Node Package Manager (NPM) globally. This is a prerequisite for using the `npx` command reliably, especially when encountering issues with server loading. ```bash npm install -g npm ``` -------------------------------- ### Protocol Error Example (JSON) Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Illustrates a standard JSON-RPC protocol error response. This example shows an error with code -32602, indicating invalid arguments, specifically an unknown tool. ```json { "jsonrpc": "2.0", "id": 3, "error": { "code": -32602, "message": "Unknown tool: invalid_tool_name" } } ``` -------------------------------- ### C# Basic Client Structure Initialization (C#) Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Sets up the basic structure for a .NET client application using `Host.CreateApplicationBuilder`. It configures the application to read settings from environment variables, which is essential for loading configurations like API keys. ```csharp using Anthropic.SDK; using Microsoft.Extensions.AI; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using ModelContextProtocol.Client; using ModelContextProtocol.Protocol.Transport; var builder = Host.CreateApplicationBuilder(args); builder.Configuration .AddEnvironmentVariables() ``` -------------------------------- ### Initialize Node.js MCP Client Project Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Commands to create a new TypeScript project, install necessary MCP and Anthropic SDK dependencies, and initialize the environment. ```bash mkdir mcp-client-typescript cd mcp-client-typescript npm init -y npm install @anthropic-ai/sdk @modelcontextprotocol/sdk dotenv npm install -D @types/node typescript touch index.ts ``` ```powershell md mcp-client-typescript cd mcp-client-typescript npm init -y npm install @anthropic-ai/sdk @modelcontextprotocol/sdk dotenv npm install -D @types/node typescript new-item index.ts ``` -------------------------------- ### Initialize and Run MCP Server Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Sets up the main function to connect the MCP server using StdioServerTransport and handles potential startup errors. ```typescript async function main() { const transport = new StdioServerTransport(); await server.connect(transport); console.error("Weather MCP Server running on stdio"); } main().catch((error) => { console.error("Fatal error in main():", error); process.exit(1); }); ``` -------------------------------- ### Initialize C# Console Project Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Commands to create a new directory and initialize a C# console application using the .NET CLI. ```bash mkdir weather cd weather dotnet new console ``` -------------------------------- ### MCP JSON-RPC Error Response Example Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Provides an example of a JSON-RPC error response format used by MCP clients to report common failure cases. It includes a standard JSON-RPC structure with an 'error' object containing 'code' and 'message'. ```json { "jsonrpc": "2.0", "id": 1, "error": { "code": -1, "message": "User rejected sampling request" } } ``` -------------------------------- ### GET tools/list Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Retrieves the list of tools available on the server. ```APIDOC ## GET tools/list ### Description Returns a list of all tools exposed by the MCP server. ### Method GET ### Endpoint tools/list ### Response #### Success Response (200) - **tools** (array) - List of tool definitions including name, description, and input schema. ``` -------------------------------- ### Building the MCP Server JAR Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt This bash command compiles and packages the Spring Boot application into an executable JAR file. The command 'mvnw clean install' cleans previous builds, compiles the code, runs tests, and installs the artifact into the local Maven repository, producing a JAR file in the 'target' directory. ```bash ./mvnw clean install ``` -------------------------------- ### Implement MCP Server Prompts (Python) Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt This Python code demonstrates setting up an MCP server and defining handlers for prompt functionalities. It mirrors the TypeScript example by providing 'git-commit' and 'explain-code' prompts. The server is initialized, and decorators are used to register functions for listing and retrieving prompts, handling arguments, and constructing message content. ```python from mcp.server import Server import mcp.types as types # Define available prompts PROMPTS = { "git-commit": types.Prompt( name="git-commit", description="Generate a Git commit message", arguments=[ types.PromptArgument( name="changes", description="Git diff or description of changes", required=True ) ], ), "explain-code": types.Prompt( name="explain-code", description="Explain how code works", arguments=[ types.PromptArgument( name="code", description="Code to explain", required=True ), types.PromptArgument( name="language", description="Programming language", required=False ) ], ) } # Initialize server app = Server("example-prompts-server") @app.list_prompts() async def list_prompts() -> list[types.Prompt]: return list(PROMPTS.values()) @app.get_prompt() async def get_prompt( name: str, arguments: dict[str, str] | None = None ) -> types.GetPromptResult: if name not in PROMPTS: raise ValueError(f"Prompt not found: {name}") if name == "git-commit": changes = arguments.get("changes") if arguments else "" return types.GetPromptResult( messages=[ types.PromptMessage( role="user", content=types.TextContent( type="text", text=f"Generate a concise but descriptive commit message " f"for these changes:\n\n{changes}" ) ) ] ) if name == "explain-code": code = arguments.get("code") if arguments else "" language = arguments.get("language", "Unknown") if arguments else "Unknown" return types.GetPromptResult( messages=[ types.PromptMessage( role="user", content=types.TextContent( type="text", text=f"Explain how this {language} code works:\n\n{code}" ) ) ] ) raise ValueError("Prompt implementation not found") ``` -------------------------------- ### GET prompts/list Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Retrieves a paginated list of all available prompt templates provided by the server. ```APIDOC ## POST prompts/list ### Description Retrieves a list of available prompt templates. Supports pagination via a cursor. ### Method POST (JSON-RPC) ### Endpoint prompts/list ### Parameters #### Query Parameters - **cursor** (string) - Optional - Pagination cursor for retrieving subsequent pages. ### Request Example { "jsonrpc": "2.0", "id": 1, "method": "prompts/list", "params": { "cursor": "optional-cursor-value" } } ### Response #### Success Response (200) - **prompts** (array) - List of available prompt objects. - **nextCursor** (string) - Cursor for the next page of results. #### Response Example { "jsonrpc": "2.0", "id": 1, "result": { "prompts": [ { "name": "code_review", "title": "Request Code Review", "description": "Asks the LLM to analyze code quality", "arguments": [{ "name": "code", "description": "The code to review", "required": true }] } ], "nextCursor": "next-page-cursor" } } ``` -------------------------------- ### POST /initialize Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Initiates the connection between client and server, negotiating protocol versions and capabilities. ```APIDOC ## POST /initialize ### Description The client sends an initialize request to establish protocol version compatibility and exchange capabilities. ### Method POST ### Endpoint /initialize ### Request Body - **protocolVersion** (string) - Required - The protocol version supported by the client. - **capabilities** (object) - Required - The client's supported features (e.g., roots, sampling). - **clientInfo** (object) - Required - Metadata about the client implementation. ### Request Example { "jsonrpc": "2.0", "id": 1, "method": "initialize", "params": { "protocolVersion": "2024-11-05", "capabilities": { "roots": { "listChanged": true } }, "clientInfo": { "name": "ExampleClient", "version": "1.0.0" } } } ### Response #### Success Response (200) - **protocolVersion** (string) - The negotiated protocol version. - **capabilities** (object) - The server's supported features. - **serverInfo** (object) - Metadata about the server implementation. #### Response Example { "jsonrpc": "2.0", "id": 1, "result": { "protocolVersion": "2024-11-05", "capabilities": { "tools": { "listChanged": true } }, "serverInfo": { "name": "ExampleServer", "version": "1.0.0" } } } ``` -------------------------------- ### Implement MCP Server Prompts (TypeScript) Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt This TypeScript code demonstrates how to set up an MCP server and define handlers for listing and retrieving prompts. It includes two example prompts: 'git-commit' for generating commit messages and 'explain-code' for explaining code snippets. The server listens for requests and responds with the appropriate prompt messages. ```typescript import { Server } from "@modelcontextprotocol/sdk/server"; import { ListPromptsRequestSchema, GetPromptRequestSchema } from "@modelcontextprotocol/sdk/types"; const PROMPTS = { "git-commit": { name: "git-commit", description: "Generate a Git commit message", arguments: [ { name: "changes", description: "Git diff or description of changes", required: true } ] }, "explain-code": { name: "explain-code", description: "Explain how code works", arguments: [ { name: "code", description: "Code to explain", required: true }, { name: "language", description: "Programming language", required: false } ] } }; const server = new Server({ name: "example-prompts-server", version: "1.0.0" }, { capabilities: { prompts: {} } }); // List available prompts server.setRequestHandler(ListPromptsRequestSchema, async () => { return { prompts: Object.values(PROMPTS) }; }); // Get specific prompt server.setRequestHandler(GetPromptRequestSchema, async (request) => { const prompt = PROMPTS[request.params.name]; if (!prompt) { throw new Error(`Prompt not found: ${request.params.name}`); } if (request.params.name === "git-commit") { return { messages: [ { role: "user", content: { type: "text", text: `Generate a concise but descriptive commit message for these changes:\n\n${request.params.arguments?.changes}` } } ] }; } if (request.params.name === "explain-code") { const language = request.params.arguments?.language || "Unknown"; return { messages: [ { role: "user", content: { type: "text", text: `Explain how this ${language} code works:\n\n${request.params.arguments?.code}` } } ] }; } throw new Error("Prompt implementation not found"); }); ``` -------------------------------- ### GET /.well-known/oauth-authorization-server Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Retrieves metadata for the authorization server to understand supported capabilities and endpoints. ```APIDOC ## GET /.well-known/oauth-authorization-server ### Description Retrieves the Authorization Server Metadata as defined in RFC 8414. This allows the client to discover endpoints for authorization, token issuance, and other OAuth 2.1 capabilities. ### Method GET ### Endpoint /.well-known/oauth-authorization-server ### Response #### Success Response (200) - **issuer** (string) - The authorization server's issuer identifier. - **authorization_endpoint** (string) - URL of the authorization endpoint. - **token_endpoint** (string) - URL of the token endpoint. #### Response Example { "issuer": "https://as.example.com", "authorization_endpoint": "https://as.example.com/authorize", "token_endpoint": "https://as.example.com/token" } ``` -------------------------------- ### Fetch Official Documentation by URL Source: https://github.com/exa-labs/exa-mcp-server/blob/main/skills/search/references/patterns-code.md Use `web_fetch_exa` to retrieve official documentation directly when you have the specific URL. This is useful for accessing precise information from official sources. ```shell web_fetch_exa ``` -------------------------------- ### GET /get-forecast Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Retrieves the weather forecast for a specific location defined by latitude and longitude. ```APIDOC ## GET /get-forecast ### Description Retrieves the weather forecast for a given location by fetching grid point data from the NWS API and returning the formatted forecast periods. ### Method GET ### Endpoint get-forecast ### Parameters #### Query Parameters - **latitude** (number) - Required - Latitude of the location (-90 to 90) - **longitude** (number) - Required - Longitude of the location (-180 to 180) ### Request Example { "latitude": 39.7456, "longitude": -97.0892 } ### Response #### Success Response (200) - **content** (array) - An array containing a text object with the formatted weather forecast. #### Response Example { "content": [ { "type": "text", "text": "Forecast for 39.7456, -97.0892:\n\nTonight:\nTemperature: 65°F\nWind: 10 mph S\nClear\n---" } ] } ``` -------------------------------- ### Boolean Schema Example (JSON) Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Defines a schema for boolean types, including a default value. ```json { "type": "boolean", "title": "Display Name", "description": "Description text", "default": false } ``` -------------------------------- ### Initialize Kotlin MCP Project Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Commands to initialize a new Kotlin project for MCP development across different operating systems. ```bash # Create a new directory for our project mkdir weather cd weather # Initialize a new kotlin project gradle init ``` ```powershell # Create a new directory for our project md weather cd weather # Initialize a new kotlin project gradle init ``` -------------------------------- ### Build and Run Brave Chatbot (Alternative) Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Alternative commands to build and run the Brave Chatbot application, first by building the JAR file and then executing it, or by using Maven's spring-boot:run. ```bash ./mvnw clean install java -jar ./target/ai-mcp-brave-chatbot-0.0.1-SNAPSHOT.jar ``` ```bash ./mvnw spring-boot:run ``` -------------------------------- ### GET /list-operations Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Standardized pagination pattern for listing resources, templates, prompts, and tools in MCP. ```APIDOC ## GET /list-operations ### Description Retrieves a paginated list of items for resources, templates, prompts, or tools. Clients must treat cursors as opaque tokens. ### Method GET ### Endpoint /resources/list, /resources/templates/list, /prompts/list, /tools/list ### Parameters #### Query Parameters - **cursor** (string) - Optional - An opaque token representing the current position in the result set. ### Response #### Success Response (200) - **items** (array) - The list of requested objects. - **nextCursor** (string) - Optional - Token for the next page of results. If missing, it indicates the end of results. #### Error Handling - **-32602** (Invalid params) - Returned if an invalid or expired cursor is provided. ``` -------------------------------- ### MCP Client Initialization with Roots Capability (JSON) Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Shows how a client declares the 'roots' capability during initialization, indicating support for managing filesystem roots and whether it will emit change notifications. ```json { "capabilities": { "roots": { "listChanged": true } } } ``` -------------------------------- ### GET prompts/get Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Retrieves the content of a specific prompt template, optionally populated with provided arguments. ```APIDOC ## POST prompts/get ### Description Retrieves the full content of a specific prompt by name, including the message structure. ### Method POST (JSON-RPC) ### Endpoint prompts/get ### Parameters #### Request Body - **name** (string) - Required - The unique name of the prompt. - **arguments** (object) - Optional - Key-value pairs matching the prompt's defined arguments. ### Request Example { "jsonrpc": "2.0", "id": 2, "method": "prompts/get", "params": { "name": "code_review", "arguments": { "code": "def hello():\n print('world')" } } } ### Response #### Success Response (200) - **description** (string) - Description of the prompt. - **messages** (array) - The structured messages to be sent to the LLM. #### Response Example { "jsonrpc": "2.0", "id": 2, "result": { "description": "Code review prompt", "messages": [ { "role": "user", "content": { "type": "text", "text": "Please review this Python code:\ndef hello():\n print('world')" } } ] } } ``` -------------------------------- ### Multiple Repositories Root Definitions (JSON) Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt This example shows how to define multiple roots, representing different repositories or project directories. Each object in the array follows the standard root definition structure. ```json [ { "uri": "file:///home/user/repos/frontend", "name": "Frontend Repository" }, { "uri": "file:///home/user/repos/backend", "name": "Backend Repository" } ] ``` -------------------------------- ### GET roots/list Source: https://github.com/exa-labs/exa-mcp-server/blob/main/llm_mcp_docs.txt Retrieves the list of filesystem roots that the server has access to within the client environment. ```APIDOC ## GET roots/list ### Description Requests the client to provide a list of filesystem roots, defining the boundaries of where the server can operate. ### Method GET ### Endpoint roots/list ### Parameters None ### Request Example { "jsonrpc": "2.0", "id": 1, "method": "roots/list" } ### Response #### Success Response (200) - **roots** (array) - A list of root objects containing a URI and a display name. #### Response Example { "jsonrpc": "2.0", "id": 1, "result": { "roots": [ { "uri": "file:///home/user/projects/myproject", "name": "My Project" } ] } } ```