### Create and Start a Simple MCP Server (TypeScript) Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/README.md Demonstrates how to create a configurable SimpleServer using the '@l4t/mcp-ai/simple-server' library. It includes defining tools, configuring server connection details (HTTP in this example), starting the server, and stopping it. Dependencies include the '@l4t/mcp-ai/simple-server' package. ```typescript import { create } from '@l4t/mcp-ai/simple-server' // Create a simple server configuration const config = { name: 'my-mcp-server', version: '1.0.0', tools: [ { name: 'echo', description: 'Echoes back the input', inputSchema: { type: 'object', properties: { message: { type: 'string' }, }, required: ['message'], }, execute: async (input: { message: string }) => { return { echo: input.message } }, }, ], server: { connection: { type: 'http', port: 3000, }, }, } // Create and start the server const server = create(config) await server.start() // The server will now be available at http://localhost:3000 // It will expose the echo tool and handle all MCP protocol details // When done, stop the server await server.stop() ``` -------------------------------- ### Full MCP Configuration Example Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/README.md This example demonstrates a complete configuration combining a CLI integrator for AWS Bedrock with a CLI server and a filesystem MCP. ```json { "integrator": { "connection": { "type": "cli", "path": "tsx", "args": ["./bin/cliServer.mts", "./config.json"] }, "provider": "aws-bedrock-claude", "model": "anthropic.claude-3-5-sonnet-20241022-v2:0", "modelId": "arn:aws:bedrock:us-east-1:461659650211:inference-profile/us.anthropic.claude-3-5-sonnet-20241022-v2:0", "maxParallelCalls": 1 }, "aggregator": { "server": { "connection": { "type": "cli" }, "maxParallelCalls": 10 }, "mcps": [ { "id": "filesystem", "connection": { "type": "cli", "path": "npx", "args": ["-y", "@modelcontextprotocol/server-memory"] } } ] } } ``` -------------------------------- ### Simple Server Configuration Examples (JSON) Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/README.md Provides JSON configurations for setting up a SimpleServer with different connection types: HTTP, SSE, and CLI. Each example defines the server's name, version, tools, and specific server connection parameters like port and paths. These configurations allow easy adaptation of the server to various deployment scenarios. ```json { "name": "my-mcp-server", "version": "1.0.0", "tools": [ { "name": "echo", "description": "Echoes back the input", "inputSchema": { "type": "object", "properties": { "message": { "type": "string" } }, "required": ["message"] } } ], "server": { "connection": { "type": "http", "port": 3000 } } } ``` ```json { "name": "my-mcp-server", "version": "1.0.0", "tools": [ { "name": "echo", "description": "Echoes back the input", "inputSchema": { "type": "object", "properties": { "message": { "type": "string" } }, "required": ["message"] } } ], "server": { "connection": { "type": "sse", "port": 3000 }, "path": "/", "messagesPath": "/messages" } } ``` ```json { "name": "my-mcp-server", "version": "1.0.0", "tools": [ { "name": "echo", "description": "Echoes back the input", "inputSchema": { "type": "object", "properties": { "message": { "type": "string" } }, "required": ["message"] } } ], "server": { "connection": { "type": "cli" } } } ``` -------------------------------- ### Install MCP AI Library with npm Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/README.md Installs the MCP AI library using npm. This is the first step to using the library's aggregation and integration features. ```bash npm install @l4t/mcp-ai ``` -------------------------------- ### Launch CLI Aggregator with Mixed Connection Types Source: https://context7.com/leadership-4-tech/mcp-ai/llms.txt Launches an MCP aggregator from the command line using a configuration file. This example demonstrates how to support mixed connection types (HTTP, CLI, SSE) for different MCPs within a single aggregator instance. It requires the '@l4t/mcp-ai' and 'argparse' npm packages, and a JSON configuration file. ```bash npm install -g @l4t/mcp-ai argparse cat > aggregator-config.json << 'EOF' { "server": { "connection": { "type": "http", "port": 3000 }, "maxParallelCalls": 10 }, "mcps": [ { "id": "filesystem", "connection": { "type": "cli", "path": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "."], "env": { "NODE_ENV": "production" } } }, { "id": "remote-tools", "connection": { "type": "sse", "url": "http://tools.example.com:8080" } } ] } EOF mcp-aggregator.js ./aggregator-config.json ``` -------------------------------- ### Install and Run MCP Aggregator from CLI (Bash) Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/README.md Instructions for globally installing the MCP aggregator script using npm, which requires '@l4t/mcp-ai' and 'argparse'. It then shows how to execute the aggregator script from the command line, pointing it to a JSON configuration file. This is useful for running MCP servers in containerized environments like Docker. ```bash npm i -g @l4t/mcp-ai argparse ``` ```bash mcp-aggregator.js ./path-to-your-config.json ``` -------------------------------- ### Configure SSE Server with MCP AI Source: https://context7.com/leadership-4-tech/mcp-ai/llms.txt Configures a SimpleServer or Aggregator to use Server-Sent Events (SSE) transport for streaming connections. This example shows how to define tools with input schemas and execution logic, and how to set up the server connection details including paths for messages. It requires the 'create' function from '@l4t/mcp-ai/simple-server'. ```typescript import { create } from '@l4t/mcp-ai/simple-server' const sseServer = create({ name: 'streaming-tools', version: '1.0.0', tools: [ { name: 'analyze_logs', description: 'Analyze log files for patterns', inputSchema: { type: 'object', properties: { logPath: { type: 'string' }, pattern: { type: 'string' } }, required: ['logPath'] }, execute: async (input) => { const analysis = await analyzeLogFile(input.logPath, input.pattern) return { content: [{ type: 'text', text: JSON.stringify(analysis) }] } } } ], server: { connection: { type: 'sse', port: 3000 }, path: '/', messagesPath: '/messages' } }) await sseServer.start() console.log('SSE server started at http://localhost:3000') ``` -------------------------------- ### Configure HTTP Server and Filesystem MCP Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/README.md This configuration sets up an HTTP server with a specified port and path, along with a filesystem MCP component using a CLI connection. ```json { "aggregator": { "server": { "connection": { "type": "http", "url": "http://localhost:3000", "port": 3000 }, "path": "/", "maxParallelCalls": 10 }, "mcps": [ { "id": "filesystem", "connection": { "type": "cli", "path": "npx", "args": ["-y", "@modelcontextprotocol/server-memory"] } } ] } } ``` -------------------------------- ### Initialize MCP Integrator with OpenAI Source: https://context7.com/leadership-4-tech/mcp-ai/llms.txt Creates an integrator instance to connect an LLM provider (OpenAI) to MCP servers. It handles tool formatting, extraction, and execution, supporting automatic protocol translation. Requires an OpenAI API key and specifies the connection details for the MCP server. ```typescript import { createIntegrator } from '@l4t/mcp-ai/integrator' import { Provider } from '@l4t/mcp-ai' import OpenAI from 'openai' const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY }) const integrator = createIntegrator({ connection: { type: 'http', url: 'http://localhost:3000', headers: { 'Content-Type': 'application/json' } }, provider: Provider.OpenAI, model: 'gpt-4-turbo-preview', maxParallelCalls: 1 }) await integrator.connect() try { const tools = await integrator.getTools() const formattedTools = integrator.formatToolsForProvider(tools) const response = await openai.chat.completions.create({ model: 'gpt-4-turbo-preview', messages: [{ role: 'user', content: 'List files in current directory' }], tools: formattedTools }) const toolCalls = integrator.extractToolCalls(response) const results = await integrator.executeToolCalls(toolCalls) console.log('Tool execution results:', results) } finally { await integrator.disconnect() } ``` -------------------------------- ### Run List Tools Test with Configuration Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/test/listToolsHttp/README.md Executes a test script to list available tools by integrating MCP Integrator and Aggregator over HTTP. Requires a JSON configuration file specifying AI provider and connection details. ```bash tsx ./bin/listTools.mts ./path/to/your/config.json ``` -------------------------------- ### Run MCP AI Chat Test with Configuration Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/test/chat/README.md This command initiates the interactive chat test for the MCP Integrator. It requires a path to a JSON configuration file that specifies the AI provider, model details, and connection settings. Ensure all necessary environment variables and credentials are set before running. ```bash tsx ./bin/chat.mts ./path/to/your/config.json ``` -------------------------------- ### Create Simple MCP Server with Tools Source: https://context7.com/leadership-4-tech/mcp-ai/llms.txt Builds a configurable MCP server that allows defining tools with execution logic. The library manages MCP protocol details. This server can be deployed via HTTP, SSE, or CLI using the same tool definitions. ```typescript import { create } from '@l4t/mcp-ai/simple-server' const server = create({ name: 'weather-mcp-server', version: '1.0.0', tools: [ { name: 'get_weather', description: 'Get current weather for a location', inputSchema: { type: 'object', properties: { location: { type: 'string', description: 'City name' }, unit: { type: 'string', enum: ['celsius', 'fahrenheit'] } }, required: ['location'] }, execute: async (input) => { const weather = await fetchWeather(input.location, input.unit) return { content: [{ type: 'text', text: JSON.stringify({ location: input.location, temperature: weather.temp, condition: weather.condition }) }] } } }, { name: 'get_forecast', description: 'Get 5-day weather forecast', inputSchema: { type: 'object', properties: { location: { type: 'string' } }, required: ['location'] }, execute: async (input) => { const forecast = await fetchForecast(input.location) return { content: [{ type: 'text', text: JSON.stringify(forecast) }] } } } ], server: { connection: { type: 'http', port: 3000 } } }) await server.start() console.log('Weather MCP server running on port 3000') ``` -------------------------------- ### Configure SSE Server and Filesystem MCP Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/README.md This configuration defines an SSE server with specified URLs, ports, and paths, alongside a filesystem MCP component using a CLI connection. ```json { "aggregator": { "server": { "connection": { "type": "sse", "url": "http://localhost:3000", "port": 3000 }, "path": "/", "messagesPath": "/messages", "maxParallelCalls": 10 }, "mcps": [ { "id": "filesystem", "connection": { "type": "cli", "path": "npx", "args": ["-y", "@modelcontextprotocol/server-memory"] } } ] } } ``` -------------------------------- ### Configure CLI Server and Filesystem MCP Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/README.md This configuration defines a CLI server with a maximum of 10 parallel calls and a filesystem MCP component also using a CLI connection. ```json { "aggregator": { "server": { "connection": { "type": "cli" }, "maxParallelCalls": 10 }, "mcps": [ { "id": "filesystem", "connection": { "type": "cli", "path": "npx", "args": ["-y", "@modelcontextprotocol/server-memory"] } } ] } } ``` -------------------------------- ### Create an Integrator for LLM Connections Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/README.md Creates an integrator to connect an LLM to an MCP server. It handles tool formatting, extraction of tool calls, and execution. Requires configuration for connection, LLM provider, model, and parallel calls. ```typescript import { createIntegrator } from '@l4t/mcp-ai/integrator' import { Provider } from '@l4t/mcp-ai' // Create an integrator configuration const config = { connection: { type: 'http', url: 'http://localhost:3000', headers: { 'Content-Type': 'application/json', }, }, provider: Provider.OpenAI, model: 'gpt-4-turbo-preview', maxParallelCalls: 1, } // Initialize the integrator const integrator = createIntegrator(config) // Connect to the MCP server await integrator.connect() try { // Get available tools const tools = await integrator.getTools() // Format tools for the LLM provider const formattedTools = integrator.formatToolsForProvider(tools) // Example of using the integrator with an LLM const response = await llm.sendMessage('List available tools', formattedTools) // Extract tool calls from the LLM response const toolCalls = integrator.extractToolCalls(response) // Execute the tool calls const results = await integrator.executeToolCalls(toolCalls) // Create a new request with the tool results const newRequest = integrator.createToolResponseRequest( originalRequest, response, results ) } finally { // Always disconnect when done await integrator.disconnect() } ``` -------------------------------- ### Full Integration: Integrator & Aggregator with MCP AI (TypeScript) Source: https://context7.com/leadership-4-tech/mcp-ai/llms.txt This snippet demonstrates a full integration where an Integrator connects to an Aggregator managing multiple MCP servers (filesystem and memory). It sets up the aggregator, connects the integrator, formats tools for an LLM provider (Anthropic Claude), executes tool calls, and processes the results. Dependencies include '@l4t/mcp-ai', '@anthropic-ai/sdk'. ```typescript import { create as createAggregator } from '@l4t/mcp-ai/aggregator' import { createIntegrator } from '@l4t/mcp-ai/integrator' import { Provider } from '@l4t/mcp-ai' import Anthropic from '@anthropic-ai/sdk' // Start aggregator with multiple MCP servers const aggregator = createAggregator({ server: { connection: { type: 'http', port: 3000 } }, mcps: [ { id: 'fs', connection: { type: 'cli', path: 'npx', args: ['-y', '@modelcontextprotocol/server-filesystem', '.'] } }, { id: 'mem', connection: { type: 'cli', path: 'npx', args: ['-y', '@modelcontextprotocol/server-memory'] } } ] }) await aggregator.connect() // Connect integrator to aggregator const integrator = createIntegrator({ connection: { type: 'http', url: 'http://localhost:3000' }, provider: Provider.Claude, model: 'claude-3-5-sonnet-20240620' }) await integrator.connect() const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY }) const tools = integrator.formatToolsForProvider(await integrator.getTools()) const response = await client.messages.create({ model: 'claude-3-5-sonnet-20240620', max_tokens: 1024, messages: [{ role: 'user', content: 'List files and store the count in memory' }], tools: tools }) if (response.stop_reason === 'tool_use') { const toolCalls = integrator.extractToolCalls(response) const results = await integrator.executeToolCalls(toolCalls) console.log('Multi-server tool execution:', results) } await integrator.disconnect() ``` -------------------------------- ### Configure HTTP Integrator for OpenAI Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/README.md This configuration defines an HTTP integrator for connecting to OpenAI's GPT-4 Turbo Preview model. It includes the connection URL and basic headers. ```json { "integrator": { "connection": { "type": "http", "url": "http://localhost:3000", "headers": { "Content-Type": "application/json" } }, "provider": "openai", "model": "gpt-4-turbo-preview", "maxParallelCalls": 1 } } ``` -------------------------------- ### Create MCP Aggregator Server Source: https://context7.com/leadership-4-tech/mcp-ai/llms.txt Creates an aggregator server that unifies multiple MCP servers under a single interface. It supports various transport protocols and enables translation between different MCP connection types (CLI, HTTP). Configuration includes server connection details and a list of MCP servers to aggregate. ```typescript import { create } from '@l4t/mcp-ai/aggregator' const aggregator = create({ server: { connection: { type: 'http', url: 'http://localhost:3000', port: 3000 }, maxParallelCalls: 10 }, mcps: [ { id: 'filesystem', connection: { type: 'cli', path: 'npx', args: ['-y', '@modelcontextprotocol/server-filesystem', '/workspace'] } }, { id: 'memory', connection: { type: 'cli', path: 'npx', args: ['-y', '@modelcontextprotocol/server-memory'] } }, { id: 'remote-api', connection: { type: 'http', url: 'http://api.example.com/mcp', headers: { 'Authorization': 'Bearer token123' }, timeout: 5000 } } ] }) await aggregator.connect() console.log('Aggregator running on http://localhost:3000') ``` -------------------------------- ### Configure HTTP MCP Connection for Filesystem Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/README.md This configuration defines an HTTP MCP connection for a 'filesystem' component, including the URL, authorization headers, and retry settings. ```json { "id": "filesystem", "connection": { "type": "http", "url": "http://localhost:3001", "headers": { "Authorization": "Bearer your-token" }, "timeout": 5000, "retry": { "attempts": 3, "backoff": 1000 } } } ``` -------------------------------- ### Create an Aggregator for Multiple MCP Servers Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/README.md Creates an aggregator server to combine multiple MCP servers into a single interface. It allows for adapting different MCP server types. Requires configuration for server connection and details of the MCPs to aggregate. ```typescript import { create } from '@l4t/mcp-ai/aggregator' // Create an aggregator configuration const config = { server: { connection: { type: 'http', url: 'http://localhost:3000', port: 3000, }, maxParallelCalls: 10, }, mcps: [ { id: 'filesystem', connection: { type: 'cli', path: 'npx', args: ['-y', '@modelcontextprotocol/server-memory'], }, }, { id: 'memory', connection: { type: 'cli', path: 'npx', args: ['-y', '@modelcontextprotocol/server-filesystem', '.'], }, }, ], } // Create and start the aggregator server const server = create(config) // Start the server await server.start() // The server will now be available at http://localhost:3000 // It will aggregate the tools from both the filesystem and memory MCPs // When done, stop the server await server.stop() ``` -------------------------------- ### Create Follow-up Request with Tool Results using MCP AI Integrator Source: https://context7.com/leadership-4-tech/mcp-ai/llms.txt Constructs a follow-up request to send tool execution results back to an LLM provider. This function is essential for maintaining conversation context after tool interactions. It requires the initial request, the LLM's response, and the tool execution results as input. The output is a formatted request object suitable for subsequent LLM calls. ```typescript import { createIntegrator } from '@l4t/mcp-ai/integrator' import { Provider } from '@l4t/mcp-ai' import OpenAI from 'openai' const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY }) const integrator = createIntegrator({ connection: { type: 'http', url: 'http://localhost:3000' }, provider: Provider.OpenAI, model: 'gpt-4-turbo-preview' }) await integrator.connect() const tools = integrator.formatToolsForProvider(await integrator.getTools()) const initialRequest = { model: 'gpt-4-turbo-preview', messages: [{ role: 'user', content: 'What files are in the current directory?' }], tools: tools } const response = await openai.chat.completions.create(initialRequest) const toolCalls = integrator.extractToolCalls(response) const results = await integrator.executeToolCalls(toolCalls) const followUpRequest = integrator.createToolResponseRequest( initialRequest, response, results ) const finalResponse = await openai.chat.completions.create(followUpRequest) console.log(finalResponse.choices[0].message.content) await integrator.disconnect() ``` -------------------------------- ### Configure CLI MCP Connection for Memory Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/README.md This configuration shows a CLI MCP connection for a 'memory' component, including the command to execute, environment variables, and working directory. ```json { "id": "memory", "connection": { "type": "cli", "path": "npx", "args": ["-y", "@modelcontextprotocol/server-memory"], "env": { "MEMORY_PATH": "./data" }, "cwd": "./" } } ``` -------------------------------- ### Configure CLI Integrator for AWS Bedrock Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/README.md This configuration sets up a CLI integrator to connect to AWS Bedrock using the Claude 3.5 Sonnet model. It specifies the command to execute and the model details. ```json { "integrator": { "connection": { "type": "cli", "path": "tsx", "args": ["./bin/cliServer.mts", "./config.json"] }, "provider": "aws-bedrock-claude", "model": "anthropic.claude-3-5-sonnet-20241022-v2:0", "modelId": "arn:aws:bedrock:us-east-1:461659650211:inference-profile/us.anthropic.claude-3-5-sonnet-20241022-v2:0", "maxParallelCalls": 1 } } ``` -------------------------------- ### Execute Tool Calls with MCP AI Integrator Source: https://context7.com/leadership-4-tech/mcp-ai/llms.txt Executes a list of tool calls on a connected MCP server using the 'executeToolCalls' method. It requires the 'createIntegrator' function and a 'Provider' enum. The input is an array of tool call objects, and the output is an array of results, each with an id and content indicating success or retrieved data. ```typescript import { createIntegrator } from '@l4t/mcp-ai/integrator' import { Provider } from '@l4t/m4p-ai' const integrator = createIntegrator({ connection: { type: 'cli', path: 'npx', args: ['-y', '@modelcontextprotocol/server-memory'] }, provider: Provider.OpenAI, maxParallelCalls: 3 }) await integrator.connect() const toolCalls = [ { id: 'call_1', name: 'store_memory', input: { key: 'user', value: 'Alice' } }, { id: 'call_2', name: 'store_memory', input: { key: 'age', value: '30' } }, { id: 'call_3', name: 'retrieve_memory', input: { key: 'user' } } ] const results = await integrator.executeToolCalls(toolCalls) // results format: // [ // { id: 'call_1', content: { success: true } }, // { id: 'call_2', content: { success: true } }, // { id: 'call_3', content: { key: 'user', value: 'Alice' } } // ] console.log('Tool execution results:', results) await integrator.disconnect() ``` -------------------------------- ### Configure SSE MCP Connection for Streaming Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/README.md This configuration sets up an SSE MCP connection for a 'streaming' component, specifying the SSE endpoint URL. ```json { "id": "streaming", "connection": { "type": "sse", "url": "http://localhost:3002" } } ``` -------------------------------- ### Configure WebSocket MCP Connection for Realtime Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/README.md This configuration defines a WebSocket MCP connection for a 'realtime' component, including the URL, protocols, authorization headers, and reconnection settings. ```json { "id": "realtime", "connection": { "type": "ws", "url": "ws://localhost:3003", "protocols": ["mcp-v1"], "headers": { "Authorization": "Bearer your-token" }, "reconnect": { "attempts": 5, "backoff": 1000 } } } ``` -------------------------------- ### Claude API Direct Response Schema (Tool Call) Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/docs/implementation/schemas.md Illustrates the JSON response from the direct Claude API when it decides to use a tool. It includes message metadata, the type of response, and the tool_use content detailing the tool name and its inputs. The stop_reason indicates that a tool was invoked. ```json { "id": "msg_01AbCdEfGhIjKlMnOpQrStUv", "type": "message", "role": "assistant", "model": "claude-3-5-sonnet-20240620", "content": [ { "type": "tool_use", "id": "toolu_01AbCdEfGhIjKlMnOpQrStUv", "name": "weather_tool", "input": { "location": "Seattle, WA", "unit": "fahrenheit" } } ], "stop_reason": "tool_use", "usage": { "input_tokens": 156, "output_tokens": 42 } } ``` -------------------------------- ### Configure SSE Integrator for Claude Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/README.md This configuration sets up a Server-Sent Events (SSE) integrator for the Claude 3 Opus model. It specifies the SSE endpoint URL. ```json { "integrator": { "connection": { "type": "sse", "url": "http://localhost:3000" }, "provider": "claude", "model": "claude-3-opus-20240229", "maxParallelCalls": 1 } } ``` -------------------------------- ### Claude API (Direct) - Request Schema Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/docs/implementation/schemas.md Defines the structure for sending requests to the direct Claude API, including model parameters, system prompts, messages, and tool definitions. ```APIDOC ## POST /v1/messages ### Description Sends a message to the Claude API for text generation or tool interaction. ### Method POST ### Endpoint /v1/messages ### Parameters #### Request Body - **model** (string) - Required - The model to use for generation. - **max_tokens** (integer) - Required - The maximum number of tokens to generate. - **system** (string) - Optional - A system prompt to guide the model's behavior. - **messages** (array) - Required - A list of message objects representing the conversation history. - **role** (string) - Required - The role of the message sender (user, assistant, or tool). - **content** (string or array) - Required - The content of the message. Can be text or a structured object for tool use/results. - **tools** (array) - Optional - A list of tool definitions the model can use. - **name** (string) - Required - The name of the tool. - **description** (string) - Required - A description of what the tool does. - **input_schema** (object) - Required - The JSON schema defining the input for the tool. - **temperature** (number) - Optional - Controls randomness in generation (0.0 to 1.0). - **top_p** (number) - Optional - Controls diversity in generation (0.0 to 1.0). ### Request Example ```json { "model": "claude-3-5-sonnet-20240620", "max_tokens": 1024, "system": "You are a helpful assistant that specializes in weather information.", "messages": [ { "role": "user", "content": "What\'s the weather like in Seattle today?" } ], "tools": [ { "name": "weather_tool", "description": "Get current weather information for a location", "input_schema": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state/country for which to get weather information" }, "unit": { "type": "string", "enum": ["celsius", "fahrenheit"], "description": "The temperature unit to use" } }, "required": ["location"] } } ], "temperature": 0.7, "top_p": 0.9 } ``` ### Response #### Success Response (200) - **id** (string) - Unique identifier for the message. - **type** (string) - The type of the response object (e.g., 'message'). - **role** (string) - The role of the assistant. - **model** (string) - The model used for generation. - **content** (array) - The generated content, which can be text or tool use objects. - **type** (string) - The type of content (e.g., 'tool_use', 'text'). - **id** (string) - Unique identifier for the tool use. - **name** (string) - The name of the tool that was used. - **input** (object) - The input provided to the tool. - **text** (string) - The generated text content. - **stop_reason** (string) - The reason the generation stopped (e.g., 'tool_use', 'end_turn'). - **usage** (object) - Token usage statistics. - **input_tokens** (integer) - Number of input tokens. - **output_tokens** (integer) - Number of output tokens. #### Response Example (Tool Call) ```json { "id": "msg_01AbCdEfGhIjKlMnOpQrStUv", "type": "message", "role": "assistant", "model": "claude-3-5-sonnet-20240620", "content": [ { "type": "tool_use", "id": "toolu_01AbCdEfGhIjKlMnOpQrStUv", "name": "weather_tool", "input": { "location": "Seattle, WA", "unit": "fahrenheit" } } ], "stop_reason": "tool_use", "usage": { "input_tokens": 156, "output_tokens": 42 } } ``` #### Response Example (Final Response) ```json { "id": "msg_02BcDeFgHiJkLmNoPqRsTuVw", "type": "message", "role": "assistant", "model": "claude-3-5-sonnet-20240620", "content": [ { "type": "text", "text": "The weather in Seattle today is rainy with a temperature of 52°F and humidity at 85%. It\'s a typical Seattle day - you might want to bring an umbrella if you\'re heading out!" } ], "stop_reason": "end_turn", "usage": { "input_tokens": 234, "output_tokens": 68 } } ``` ### Tool Result Request Schema This schema represents a request that includes the results of a tool execution, allowing the model to continue the conversation. ### Request Example ```json { "model": "claude-3-5-sonnet-20240620", "max_tokens": 1024, "system": "You are a helpful assistant that specializes in weather information.", "messages": [ { "role": "user", "content": "What\'s the weather like in Seattle today?" }, { "role": "assistant", "content": [ { "type": "tool_use", "id": "toolu_01AbCdEfGhIjKlMnOpQrStUv", "name": "weather_tool", "input": { "location": "Seattle, WA", "unit": "fahrenheit" } } ] }, { "role": "user", "content": [ { "type": "tool_result", "tool_use_id": "toolu_01AbCdEfGhIjKlMnOpQrStUv", "content": "{\"location\":\"Seattle, WA\",\"temperature\":\"52°F\",\"condition\":\"Rainy\",\"humidity\":\"85%\"}" } ] } ], "tools": [ { "name": "weather_tool", "description": "Get current weather information for a location", "input_schema": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state/country for which to get weather information" }, "unit": { "type": "string", "enum": ["celsius", "fahrenheit"], "description": "The temperature unit to use" } }, "required": ["location"] } } ], "temperature": 0.7, "top_p": 0.9 } ``` ``` -------------------------------- ### OpenAI API Tool Call Response Schema (JSON) Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/docs/implementation/schemas.md This schema details the structure of a response from the OpenAI API when a tool call is generated. It includes metadata like ID and creation time, and within 'choices', it specifies the tool's name and the arguments it was called with. ```json { "id": "chatcmpl-abc123def456", "object": "chat.completion", "created": 1715000000, "model": "gpt-4o-2024-08-06", "choices": [ { "index": 0, "message": { "role": "assistant", "content": null, "tool_calls": [ { "id": "call_abc123def456", "type": "function", "function": { "name": "get_weather", "arguments": "{\"location\":\"Seattle, WA\",\"unit\":\"fahrenheit\"}" } } ] }, "finish_reason": "tool_calls" } ], "usage": { "prompt_tokens": 156, "completion_tokens": 42, "total_tokens": 198 } } ``` -------------------------------- ### Format MCP Tools for LLM Provider (TypeScript) Source: https://context7.com/leadership-4-tech/mcp-ai/llms.txt Converts MCP tool definitions into the specific format required by an LLM provider, such as OpenAI, Claude, or AWS Bedrock Claude. This function ensures compatibility with different provider APIs. ```typescript import { createIntegrator } from '@l4t/mcp-ai/integrator' import { Provider } from '@l4t/mcp-ai' const integrator = createIntegrator({ connection: { type: 'cli', path: 'npx', args: ['-y', '@modelcontextprotocol/server-memory'] }, provider: Provider.Claude, model: 'claude-3-5-sonnet-20240620' }) await integrator.connect() const mcpTools = await integrator.getTools() const claudeTools = integrator.formatToolsForProvider(mcpTools) // claudeTools format for Claude: // [ // { // name: 'store_memory', // description: 'Store a piece of information in memory', // input_schema: { // type: 'object', // properties: { key: { type: 'string' }, value: { type: 'string' } }, // required: ['key', 'value'] // } // } // ] await integrator.disconnect() ``` -------------------------------- ### OpenAI Structured Output Request for Weather Data Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/docs/implementation/schemas.md This JSON schema details a request to OpenAI for structured JSON output, specifically for weather information. It specifies the model, conversation messages, and crucially, the `response_format` with a defined JSON schema for the expected output. This ensures the AI returns data in a predictable, parseable format. ```json { "model": "gpt-4o-2024-08-06", "messages": [ { "role": "system", "content": "You are a helpful assistant that provides information in a structured format." }, { "role": "user", "content": "Give me weather information for Seattle." } ], "response_format": { "type": "json_object", "schema": { "type": "object", "properties": { "location": { "type": "string" }, "current_weather": { "type": "object", "properties": { "temperature": { "type": "number" }, "unit": { "type": "string", "enum": ["celsius", "fahrenheit"] }, "condition": { "type": "string" }, "humidity": { "type": "number" } }, "required": ["temperature", "unit", "condition"] } }, "required": ["location", "current_weather"] } }, "temperature": 0.7, "max_tokens": 1024 } ``` -------------------------------- ### Extract Tool Calls from LLM Response (TypeScript) Source: https://context7.com/leadership-4-tech/mcp-ai/llms.txt Parses LLM provider responses to extract tool call requests into a unified format, abstracting away the specific structure of responses from different providers. This enables consistent handling of tool invocations. ```typescript import { createIntegrator } from '@l4t/mcp-ai/integrator' import { Provider } from '@l4t/mcp-ai' import Anthropic from '@anthropic-ai/sdk' const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY }) const integrator = createIntegrator({ connection: { type: 'http', url: 'http://localhost:3000' }, provider: Provider.Claude, model: 'claude-3-5-sonnet-20240620' }) await integrator.connect() const tools = integrator.formatToolsForProvider(await integrator.getTools()) const response = await client.messages.create({ model: 'claude-3-5-sonnet-20240620', max_tokens: 1024, messages: [{ role: 'user', content: 'Store my name as John' }], tools: tools }) const toolCalls = integrator.extractToolCalls(response) // toolCalls format (unified): // [ // { // id: 'toolu_01AbCd...', // name: 'store_memory', // input: { key: 'name', value: 'John' } // } // ] await integrator.disconnect() ``` -------------------------------- ### Tool Result Request Schema for Weather Information Source: https://github.com/leadership-4-tech/mcp-ai/blob/main/docs/implementation/schemas.md This JSON schema defines the structure for a tool result request, specifically for querying weather information. It includes the model to be used, a list of messages representing the conversation history, and the available tools with their descriptions and parameters. Dependencies include the OpenAI API and a defined `get_weather` tool. ```json { "model": "gpt-4o-2024-08-06", "messages": [ { "role": "system", "content": "You are a helpful assistant that specializes in weather information." }, { "role": "user", "content": "What's the weather like in Seattle today?" }, { "role": "assistant", "content": null, "tool_calls": [ { "id": "call_abc123def456", "type": "function", "function": { "name": "get_weather", "arguments": "{\"location\":\"Seattle, WA\",\"unit\":\"fahrenheit\"}" } } ] }, { "role": "tool", "tool_call_id": "call_abc123def456", "content": "{\"location\":\"Seattle, WA\",\"temperature\":\"52°F\",\"condition\":\"Rainy\",\"humidity\":\"85%\"}" } ], "tools": [ { "type": "function", "function": { "name": "get_weather", "description": "Get current weather information for a location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state/country for which to get weather information" }, "unit": { "type": "string", "enum": ["celsius", "fahrenheit"], "description": "The temperature unit to use" } }, "required": ["location"] } } } ], "temperature": 0.7, "max_tokens": 1024 } ```