MCP Integration
The Model Context Protocol (MCP) is an open standard for connecting AI models to external tools and data sources. LW AI supports MCP for building agentic workflows.
What is MCP?
MCP enables:
- Tool use — Models can call external functions (APIs, databases, file systems)
- Resource access — Models can read contextual data from external sources
- Prompt templates — Standardized prompt structures for consistent interactions
Using MCP with LW AI
LW AI models support MCP through function calling. Define MCP tools as function definitions in your API request:
from openai import OpenAI
client = OpenAI(
base_url="https://openapi.linkwo.ai/v1",
api_key="YOUR_API_KEY"
)
mcp_tools = [
{
"type": "function",
"function": {
"name": "query_database",
"description": "Query the company database",
"parameters": {
"type": "object",
"properties": {
"sql": {"type": "string", "description": "SQL query to execute"},
"database": {"type": "string", "enum": ["production", "staging"]}
},
"required": ["sql"]
}
}
},
{
"type": "function",
"function": {
"name": "read_file",
"description": "Read a file from the project directory",
"parameters": {
"type": "object",
"properties": {
"path": {"type": "string", "description": "File path relative to project root"}
},
"required": ["path"]
}
}
}
]
response = client.chat.completions.create(
model="deepseek/deepseek-v4-pro",
messages=[{"role": "user", "content": "Show me the user table schema"}],
tools=mcp_tools,
tool_choice="auto"
)MCP Server Setup
To expose your tools via MCP protocol, you can build an MCP server:
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const server = new McpServer({ name: "my-tools", version: "1.0.0" });
server.tool("query_database", { sql: z.string() }, async ({ sql }) => {
const results = await executeQuery(sql);
return { content: [{ type: "text", text: JSON.stringify(results) }] };
});
const transport = new StdioServerTransport();
await server.connect(transport);Compatible MCP Clients
| Client | Description |
|---|---|
| Claude Code | Terminal-based coding agent |
| Cline | VS Code autonomous agent |
| Roo Code | VS Code autonomous agent |
| Continue | VS Code AI assistant |
Best Practices
- Describe tools clearly — Good descriptions help the model choose the right tool
- Validate inputs — Sanitize tool inputs before execution
- Return structured data — Use JSON for tool results
- Handle errors — Return error messages as tool results so the model can self-correct
Related
- Function Calling — Detailed tool calling guide
- Claude Code — Claude Code configuration