Skip to main content
An MCP server (aka Model Context Protocol server), is an external service that provides data, capabilities, or tools to a Large Language Model (LLM). These servers enable LLMs to interact with other systems like databases, the internet, or local files, allowing them to perform actions, fetch information, and integrate into larger workflows by presenting their functions as tools the LLM can use. Dartantic has built-in support for mapping the tools from an MCP server, whether it’s local or running in the cloud, via a built-in McpClient class.

Remote MCP Servers

Connect to MCP servers running in the cloud:
// Connect to remote MCP server
final huggingFace = McpClient.remote(
  'huggingface',
  url: Uri.parse('https://hf.co/mcp'),
);

// Get tools from the server
final tools = await huggingFace.listTools();

// Use with your agent
final agent = Agent('google', tools: tools);
final result = await agent.send('Who is hugging face?');

Local MCP Servers

Connect to local processes running on your machine:
final calculator = McpClient.local(
  'calculator',
  command: 'npx',
  args: ['-y', '@modelcontextprotocol/server-calculator'],
);

final tools = await calculator.listTools();
final agent = Agent('anthropic', tools: [...tools]);

await agent.send('What is 15 multiplied by 27?');

Combining Multiple Sources

Mix local tools, MCP servers, and custom tools:
// Local tool
final timeTool = Tool(
  name: 'local_time',
  description: 'Get current time',
  onCall: (_) async => {'time': DateTime.now().toIso8601String()},
);

// MCP servers
final wiki = McpClient.remote('wiki', url: wikiUrl);
final hf = McpClient.remote('hf', url: hfUrl);

// Combine everything
final agent = Agent('google', tools: [
  timeTool,
  ...await wiki.listTools(),
  ...await hf.listTools(),
]);

await agent.send('What time is it and who is hugging face?');

Examples

Next Steps