- Explore MCP Servers
- ai-agent-mcp-demo
Ai Agent Mcp Demo
What is Ai Agent Mcp Demo
ai-agent-mcp-demo is a demonstration project that integrates AI agents with the Model Context Protocol (MCP), enabling AI to access specialized tools and real-time data.
Use cases
Use cases include building modular applications that separate AI reasoning from tool execution, enhancing AI capabilities with real-time data, and creating extensible systems that can incorporate new tools without retraining the AI model.
How to use
To use ai-agent-mcp-demo, set up the MCP client, establish server connections, and discover available tools through a standardized interface.
Key features
Key features include dynamic tool discovery, a standardized communication protocol, access to distributed capabilities, improved accuracy with specialized tools, enhanced security through isolated environments, and real-time data access.
Where to use
ai-agent-mcp-demo can be used in various fields such as software development, data analysis, customer support, and any domain requiring the integration of AI with specialized tools.
Clients Supporting MCP
The following are the main client software that supports the Model Context Protocol. Click the link to visit the official website for more information.
Overview
What is Ai Agent Mcp Demo
ai-agent-mcp-demo is a demonstration project that integrates AI agents with the Model Context Protocol (MCP), enabling AI to access specialized tools and real-time data.
Use cases
Use cases include building modular applications that separate AI reasoning from tool execution, enhancing AI capabilities with real-time data, and creating extensible systems that can incorporate new tools without retraining the AI model.
How to use
To use ai-agent-mcp-demo, set up the MCP client, establish server connections, and discover available tools through a standardized interface.
Key features
Key features include dynamic tool discovery, a standardized communication protocol, access to distributed capabilities, improved accuracy with specialized tools, enhanced security through isolated environments, and real-time data access.
Where to use
ai-agent-mcp-demo can be used in various fields such as software development, data analysis, customer support, and any domain requiring the integration of AI with specialized tools.
Clients Supporting MCP
The following are the main client software that supports the Model Context Protocol. Click the link to visit the official website for more information.
Content
🤖 Introduction: Integrating AI Agents with MCP

🤔 Why AI Agent Integrate with MCP?

The Model Context Protocol (MCP) addresses a fundamental limitation of AI language models: their inability to directly access specialized tools, real-time data, or external systems. By integrating AI agents with MCP, developers can:
- Overcome AI Limitations: Bridge the gap between AI’s general knowledge and specific domain capabilities
- Create Extensible Systems: Add new tools and capabilities without retraining the underlying AI model
- Build Modular Applications: Separate AI reasoning from specialized tool execution
🌟 Key Benefits of MCP Integration
- Tool Discovery: AI agents can dynamically discover available tools across multiple servers
- Standardized Interface: Consistent protocol for AI-to-tool communication
- Distributed Capabilities: Access specialized tools from various providers through a unified interface
- Improved Accuracy: Leverage purpose-built tools for specific tasks rather than relying solely on AI approximations
- Enhanced Security: Tools execute in isolated environments with defined input/output contracts
- Real-time Data Access: Connect AI responses with current information from external systems
This integration pattern transforms AI from a closed system limited by its training data into an open, extensible platform that can leverage specialized capabilities on demand.
🔄 2 Steps to Integration With MCP Server
-
🔌 MCP client setup and server connections, tool discovery
Sequence Chart
sequenceDiagram participant App as Application participant Client as MCP Client participant Transport as StdioTransport participant Server as MCP Server App->>Client: initMCPServers() App->>Transport: new StdioClientTransport(config) Transport->>Server: Start server process Client->>Transport: client.connect(transport) Transport->>Server: Send hello Server->>Transport: Hello response Transport->>Client: Connection established Client->>Server: tools/list request Server->>Client: Available tools Client->>App: Return McpServer object Note over App,Server: Server connection active App->>Client: disconnectAllServers() Client->>Transport: transport.close() Transport->>Server: Close connection Transport->>Client: onclose event Client->>App: Server disconnectedCode Example
import { Client } from "@modelcontextprotocol/sdk/client/index.js"; import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"; import { ListToolsResultSchema } from "@modelcontextprotocol/sdk/types.js"; async function connectToMcpServer(serverName, command, args = []) { // Create MCP client const client = new Client( { name: "SimpleMCPClient", version: "1.0.0" }, { capabilities: {} } ); // Create transport layer const transport = new StdioClientTransport({ command: command, args: args, env: process.env, stderr: "pipe", }); // Connect to server await client.connect(transport); // Get available tools const toolsResponse = await client.request( { method: "tools/list" }, ListToolsResultSchema ); } -
🧠 AI agent interaction
Sequence Chart
sequenceDiagram participant User participant App as Main App participant AIAgent as AI Agent participant LLM as Language Model participant McpClient as MCP Client participant Server as MCP Server User->>App: Query App->>AIAgent: processUserQuery(servers, aiModel, query) AIAgent->>LLM: generateText(systemPrompt, query) LLM->>AIAgent: Initial response with tool calls Note over AIAgent: Parse tool calls with regex loop For each tool call AIAgent->>McpClient: callMcpTool(servers, serverName, toolName, args) McpClient->>Server: tools/call request Server->>McpClient: Tool execution result McpClient->>AIAgent: Format and return result end AIAgent->>LLM: generateText with tool results LLM->>AIAgent: Final response AIAgent->>App: Return final response App->>User: Display responseCode Example
import { generateText } from "ai"; // Tool calling pattern in prompt format const systemPrompt = `You can use tools with this format: <use_mcp_tool> <server_name>server_name</server_name> <tool_name>tool_name</tool_name> <arguments> { "param1": "value1", "param2": "value2" } </arguments> </use_mcp_tool> Available tools: ${servers.map(server => `Server: ${server.name}\nTools: ${server.tools.map(t => `${t.name} - ${t.description || 'No description'}` ).join(', ')}` ).join('\n')}`; async function processWithAIAgent(model, servers, userQuery) { // Get initial AI response with potential tool calls const { text: aiResponse } = await generateText({ model, system: systemPrompt, messages: [{ role: "user", content: userQuery }] }); // Extract tool calls using regex const toolCallRegex = /<use_mcp_tool>[\s\S]*?<server_name>([\s\S]*?)<\/server_name>[\s\S]*?<tool_name>([\s\S]*?)<\/tool_name>[\s\S]*?<arguments>([\s\S]*?)<\/arguments>[\s\S]*?<\/use_mcp_tool>/g; const matches = [...aiResponse.matchAll(toolCallRegex)]; // Execute tool calls const results = []; for (const match of matches) { const serverName = match[1].trim(); const toolName = match[2].trim(); const args = JSON.parse(match[3].trim()); const server = servers.find(s => s.name === serverName); if (server) { try { // Call the MCP tool const result = await server.client.request({ method: "tools/call", params: { name: toolName, arguments: args } }); results.push({ serverName, toolName, result: result.content }); } catch (error) { results.push({ serverName, toolName, error: error.message }); } } } // Generate final response with tool results const finalResponse = await generateText({ model, system: systemPrompt, messages: [ { role: "user", content: userQuery }, { role: "assistant", content: aiResponse }, { role: "user", content: `Tool results: ${JSON.stringify(results)}` } ] }); return finalResponse.text; }This code demonstrates how an AI agent integrates with MCP tools through a structured workflow:
- 📝 A system prompt informs the AI about available MCP tools and their usage format
- 💬 The AI generates a response that may include tool calls in a structured format
- 🔍 The code parses these tool calls using regex to extract server name, tool name, and arguments
- 🛠️ For each tool call, it finds the appropriate server and executes the requested tool
- 📊 The results are collected and sent back to the AI for a final response
This approach bridges the gap between general AI language capabilities and specialized computing tasks, creating more powerful and useful AI applications.
Run the demo code locally
Check run demo file for more information
Dev Tools Supporting MCP
The following are the main code editors that support the Model Context Protocol. Click the link to visit the official website for more information.










