This document explains how to use the Model Context Protocol (MCP) integration with your AI service.
The MCP integration allows your Gemini AI client to access and use tools defined in an MCP server. This enables the AI to perform actions beyond just generating text responses.
The MCP server provides tools that can be used by AI clients:
- check-creator: Returns the project creator information
- get-project-info: Returns comprehensive project information
The AI service has been enhanced with:
- Automatic MCP server startup: The client automatically starts the MCP server process
- Native tool binding: Tools are properly bound to Gemini using the
toolsparameter - Tool execution: Automatic execution of tool calls from Gemini responses
- Tool discovery: Automatic discovery of available tools from the MCP server
The MCP server is now automatically started by the AI service when needed. You don't need to manually start it in a separate terminal.
import aiService from './services/aiService.js';
// Execute a tool directly
const result = await aiService.executeMCPTool('check-creator', {});
console.log(result);
// Get available tools
const tools = aiService.getMCPTools();
console.log(tools);// Stream response with MCP tools enabled (tools are automatically bound)
const stream = await aiService.streamGemini(
"Who created this project?",
[],
'gemini-2.0-flash-lite',
'session-1',
[],
true // Enable MCP tools
);
// Get complete response with tool execution
const response = await aiService.getGeminiResponseWithTools(
"Who created this project?",
[],
'gemini-2.0-flash-lite'
);- Automatic Initialization: When the AI service starts, it automatically starts the MCP server process
- Tool Discovery: The service discovers available tools from the MCP server
- Native Tool Binding: Tools are properly bound to Gemini using the
toolsparameter instead of prompt injection - Tool Execution: Gemini can make tool calls, which are automatically executed by the service
- Response Enhancement: Tool results are integrated into the response
Run the test script to verify the integration:
cd backend
npm run test-mcpTo add new tools to the MCP server:
-
Register the tool in
mcp-servers/index.js:server.registerTool("tool-name", { description: "Tool description", inputSchema: { type: "object", properties: {}, required: [] } }, async (args) => ({ content: [{ type: "text", text: "Tool result" }] }) );
-
The AI service will automatically discover and use the new tool
- MCP Server Startup Failed: Check that the
mcp-servers/index.jsfile exists and is valid - Tools Not Available: Verify the MCP server has registered tools and the client has connected
- Tool Execution Failed: Check the console for tool execution errors
Enable debug logging by checking the console output for:
- MCP client connection status
- Tool discovery results
- Tool execution attempts
- Tool call detection in Gemini responses
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Your App │ ┌ AI Service │ ┌ MCP Server │
│ │ │ │ │ │
│ - Chat UI │───▶│ - Gemini Client │───▶│ - Tool Registry │
│ - API Calls │ │ - MCP Client │ │ - Tool Logic │
│ │ │ - Auto Startup │ │ - Auto Process │
└─────────────────┘ └─────────────────┘ └─────────────────┘
- No Manual Server Management: MCP server starts automatically
- Native Tool Integration: Uses Gemini's built-in tool binding instead of prompt injection
- Automatic Tool Execution: Detects and executes tool calls from Gemini responses
- Better Error Handling: Graceful fallback if tools are unavailable
The AI service now acts as a complete bridge between your application and both the Gemini API and MCP tools, with automatic server management and native tool integration.