Skip to main content
MCP (Model Context Protocol) is a standard protocol that lets your agent connect to external tool servers and invoke those tools during a chat loop — using the same execution surface as local Python functions. Logicore supports MCP through MCPAgent and MCPClientManager. Together they handle server connections, tool discovery, schema conversion, and call routing, so your application code stays focused on the chat interface.

When to use MCP

For small projects with a handful of Python functions, Agent or SmartAgent is sufficient. Reach for MCP when you need:
  • Shared tool servers consumed by multiple teams or services
  • Enterprise governance — centralized control over which tools are exposed and to whom
  • Large tool ecosystems that would exceed prompt or context budgets if loaded all at once
  • Standard protocol interoperability with non-Python tooling or third-party MCP servers

Core components

MCPAgent

The agent layer. Extends Agent with MCP server integration, session lifecycle utilities, and optional deferred tool loading.

MCPClientManager

Manages stdio connections to every server in mcp.json, discovers their tools, and routes calls to the right server.

Dynamic tool loading

When the total tool count exceeds a configurable threshold, MCPAgent switches to deferred mode and exposes tools on demand.

Examples

Complete working examples covering small and large toolsets, session management, and lazy initialization.

Lifecycle summary

1

Create MCPAgent

Instantiate MCPAgent with your provider, model, and an optional mcp_config_path or mcp_config dict.
2

Initialize MCP servers

Call await agent.init_mcp_servers(), or skip it — the first chat() call triggers lazy initialization automatically.
3

Tools are merged

Internal default tools and all discovered MCP tools are merged into a unified tool list. If the total exceeds tool_threshold (default 15), deferred mode activates automatically.
4

Run the chat loop

Call await agent.chat(user_input). The agent executes tool calls, routing local tools to the built-in executor and MCP tools to the correct server session.
5

Get the response

chat() returns the final assistant message as a str, or None if no final response was produced.

What MCP adds beyond normal tools

CapabilityAgent / SmartAgentMCPAgent
Local Python tool executionYesYes (inherited)
External tool server connectionsNoYes
Tool discovery via mcp.jsonNoYes
Session lifecycle managementBasicFull (create, destroy, cleanup)
Deferred / dynamic tool loadingNoYes
Session metadata and callbacksNoYes
If you only have local tools and no external servers, start with Agent. Migrate to MCPAgent when you need any of the capabilities in the table above — the chat() API is identical, so the migration is straightforward.

Build docs developers (and LLMs) love