Intric MCP模板服务器
用于构建与Intric内置MCP客户端无缝连接的模型上下文协议(MCP)服务器的模板。此模板演示了如何创建自定义工具和资源来扩展AI助手的功能。
特性
- 工具:AI可以调用函数来执行操作
- 资源:AI可以访问的静态数据
- 资源模板:基于参数的动态资源
- 提示:用于常见交互的可重用提示模板
- 服务器元数据:Intric中显示的自定义图标、说明和版本控制
- 认证:基于JWT的API密钥验证
- IP允许列表:限制服务器对特定IP地址的访问
- 权限:控制工具/资源是否需要用户确认
运行服务器
使用uvicorn启动MCP服务器:
uvicorn server:app --host 0.0.0.0 --port 8000服务器将在以下时间可用 http://localhost:8000/mcp.
连接到Intric
在Intric的MCP连接设置中添加您暴露的服务器URL。Intric将自动发现所有可用的工具和资源。
提示:使用ngrok等服务公开绑定到本地端口的HTTPS URL,然后添加该URL(以结尾 /mcp)到Intric。
构建自己的MCP服务器
添加工具
@mcp.tool
def your_function_name(param1: str, param2: int) -> str:
"""Description of what this tool does."""
return f"Result: {param1} - {param2}"添加资源
@mcp.resource("resource://your_resource_name")
def get_your_data() -> str:
"""Description of what data this resource provides."""
return "Your data here"添加资源模板
@mcp.resource("data://{category}/{id}")
def get_dynamic_data(category: str, id: str) -> dict:
"""Provide data based on category and id."""
return {"category": category, "id": id, "data": "..."}添加提示
提示是可重用的模板,有助于标准化常见交互:
@mcp.prompt()
def code_review() -> str:
"""Review code for best practices."""
return """Please review the following code for:
- Code quality and best practices
- Potential bugs or issues
- Security concerns"""
# Prompts can accept arguments:
@mcp.prompt()
def summarize_text(style: str = "brief") -> str:
"""Summarize text in a specified style."""
if style == "bullets":
return "Summarize as a bulleted list of key points."
return "Provide a brief summary."权限
控制Intric在执行工具或访问资源之前是否要求用户确认:
# Tool that executes without user confirmation
@mcp.tool(meta={"requires_permission": False})
def auto_execute_tool() -> str:
"""This tool runs automatically without asking the user."""
return "Done"
# Resource that requires user confirmation (resources don't require permission by default)
@mcp.resource(
uri="resource://sensitive_data",
meta={"requires_permission": True},
)
def get_sensitive_data() -> str:
"""User must confirm before accessing this resource."""
return "Sensitive information"项目结构
intric-mcp-template/
├── server.py # Main server file with examples
├── tools.py # Example tool implementations
├── resources.py # Example resource implementations
├── requirements.txt # Python dependencies