MCP Client Skill
Implementation of the Model Context Protocol (MCP) client for connecting to tools and data sources.
What it does
- - Connect to MCP Servers - Access tools and resources from MCP-enabled services
- Tool Invocation - Call tools exposed by MCP servers
- Resource Access - Read files, databases, APIs
- Prompt Templates - Use structured prompts from MCP servers
Installation
CODEBLOCK0
Usage
Connect to MCP Server
CODEBLOCK1
List Available Tools
CODEBLOCK2
Call a Tool
CODEBLOCK3
List Resources
CODEBLOCK4
Read a Resource
CODEBLOCK5
MCP Concepts
- - MCP Server: Service that exposes tools, resources, and prompts
- Tools: Functions the LLM/agent can call
- Resources: Data sources (files, APIs, DBs)
- Prompts: Pre-defined prompt templates
API Reference
CODEBLOCK6
Examples
Python Usage
CODEBLOCK7
⚠️ Security Warnings
file:// URI Risk
The MCP protocol allows
file:///path URIs to read files from the server.
Only connect to trusted MCP servers. A malicious server could exfiltrate sensitive files.
Best Practices
- - Only use MCP servers you control or trust
- Don't connect to random public MCP servers
- Review what tools/resources are available before using
Requirements
- - Review what tools/resources are available before using
- - Python 3.8+
- requests library
License
MIT
MCP 客户端技能
用于连接工具和数据源的模型上下文协议(MCP)客户端实现。
功能
- - 连接 MCP 服务器 - 访问支持 MCP 的服务中的工具和资源
- 工具调用 - 调用 MCP 服务器暴露的工具
- 资源访问 - 读取文件、数据库、API
- 提示模板 - 使用 MCP 服务器提供的结构化提示
安装
powershell
安装 Python 依赖(requests 是唯一必需的依赖)
pip install requests
使用方法
连接 MCP 服务器
powershell
.\mcp.ps1 -Action connect -ServerUrl https://mcp-server.com -ApiKey your-key
列出可用工具
powershell
.\mcp.ps1 -Action tools -ServerUrl https://mcp-server.com
调用工具
powershell
.\mcp.ps1 -Action call -ServerUrl https://mcp-server.com -ToolName search -Arguments {query: AI agents}
列出资源
powershell
.\mcp.ps1 -Action resources -ServerUrl https://mcp-server.com
读取资源
powershell
.\mcp.ps1 -Action read -ServerUrl https://mcp-server.com -ResourceUri file:///data/config.json
MCP 概念
- - MCP 服务器:暴露工具、资源和提示的服务
- 工具:LLM/代理可以调用的函数
- 资源:数据源(文件、API、数据库)
- 提示:预定义的提示模板
API 参考
POST /mcp/connect - 连接服务器
GET /mcp/tools - 列出可用工具
POST /mcp/call - 调用工具
GET /mcp/resources - 列出资源
GET /mcp/read - 读取资源
GET /mcp/prompts - 列出提示模板
示例
Python 用法
python
from mcp_client import MCPClient
client = MCPClient(https://mcp-server.com, api_key=key)
列出工具
tools = client.list_tools()
print(tools)
调用工具
result = client.call_tool(search, {query: quantum})
print(result)
读取资源
data = client.read_resource(file:///config.json)
print(data)
⚠️ 安全警告
file:// URI 风险
MCP 协议允许使用 file:///path URI 从服务器读取文件。
请仅连接受信任的 MCP 服务器。 恶意服务器可能窃取敏感文件。
最佳实践
- - 仅使用您控制或信任的 MCP 服务器
- 不要连接随机的公共 MCP 服务器
- 使用前请检查可用的工具/资源
要求
许可证
MIT