Typescript sdk

MCP Servers

Copy page

Learn how to add and configure MCP servers for your agents

MCP tools connect to external servers that implement the MCP standard. This allows you to integrate with a wide ecosystem of existing tools and services.

For some tips on leveraging existing MCP server libraries or creating your own MCP server, see here.

Once you have an MCP server, now you can add it to your Agents.

Registring an MCP Server

import { agent, mcpTool } from "@inkeep/agents-sdk";

const knowledgeBaseTool = mcpTool({
  id: "knowledge-base-tool",
  name: "knowledge_base",
  description: "Search the company knowledge base for information",
  serverUrl: "https://kb.yourcompany.com/mcp",
});

const qaAgent = agent({
  id: "qa-agent",
  name: "QA Agent",
  description: "Responsible for answering questions about the company knowledge base.",
  prompt: `You are a Question-Answer agent that can answer questions about the company knowledge base.
  You have access to the knowledge base tool to search for information.`,
  canUse: () => [knowledgeBaseTool],
});
Note
Note
Tip: When adding tools to an agent, you can also reference the tool in the agent's prompt to help the agent understand how to use the tool.

Authentication

MCP servers support various authentication methods (via credentials):

  • No Authentication - For public APIs or internal services
  • API Key - For services requiring API keys
  • Bearer Token - For JWT or similar token-based authentication
  • Token Authentication - For custom token schemes
  • OAuth Flows - For standard OAuth 2.0 authentication
  • OAuth 2.1 Flows - For modern OAuth 2.1 "1-click" authentication

For OAuth flows and OAuth 2.1 flows, it's recommended to use the Visual Builder for easier configuration.

See Credentials for detailed examples and implementation guidance for each authentication type.

Custom Headers

You can configure custom headers for your MCP server requests. Use credentials for sensitive information (API keys, tokens) and headers for non-sensitive metadata (user agent, version info, etc.).

import { mcpTool } from "@inkeep/agents-sdk";

const customHeadersTool = mcpTool({
  id: "enterprise-api",
  name: "enterprise_data",
  description: "Enterprise API with custom headers",
  serverUrl: "https://enterprise.example.com/mcp",
  headers: {
    "User-Agent": "Inkeep-Agent/1.0",
    "X-Client-Version": "2024.1",
  },
});

Selecting Tools

Selective Tool Activation

Enable only specific tools from a server using MCP Server tool names in the activeTools field.

import { mcpTool } from "@inkeep/agents-sdk";

const selectiveTool = mcpTool({
  id: "limited-server",
  name: "analytics_readonly",
  description: "Analytics server with limited access",
  serverUrl: "https://analytics.example.com/mcp",
  activeTools: ["get_metrics", "generate_report"], // Only these tools
});

Using agentMcp for Tool Selection

While activeTools in mcpTool limits which tools are available from the server, you can further refine tool access at the agent level using agentMcp. This allows different agents to use different subsets of tools from the same MCP server.

import { agent, mcpTool, agentMcp } from "@inkeep/agents-sdk";

// Define the MCP server with all available tools
const echoTool = mcpTool({
  id: "echo-tool",
  name: "Echo tool",
  serverUrl: "https://mcp-for-next-js-seven-iota.vercel.app/mcp",
});

// Agent that only uses specific tools from the server
const weatherAssistant = agent({
  id: "weather-assistant",
  name: "Weather assistant",
  description: "Responsible for routing between the geocoder agent and weather forecast agent",
  prompt: "You are a helpful assistant. When the user asks about the weather in a given location, first ask the geocoder agent for the coordinates, and then pass those coordinates to the weather forecast agent to get the weather forecast",
  canDelegateTo: () => [weatherForecaster, geocoderAgent],
  canUse: () => [agentMcp({ server: echoTool, selectedTools: ["echo2"] })],
});