这是一个简单的示例,演示如何使用MCP服务器调用iFlytek SparkAgent平台的任务链。
使用stdio(默认)或SSE传输启动服务器:
# 使用stdio传输(默认)
uv run ifly-spark-agent-mcp
# 使用自定义端口上的SSE传输
uv run ifly-spark-agent-mcp --transport sse --port 8000
默认情况下,服务器会暴露一个名为“upload_file”的工具,该工具接受一个必需参数:
file: 上传文件的路径使用MCP客户端,你可以通过以下方式使用STDIO传输来调用这个工具:
import asyncio
from mcp.client.session import ClientSession
from mcp.client.stdio import StdioServerParameters, stdio_client
async def main():
async with stdio_client(
StdioServerParameters(command="uv", args=["run", "ifly-spark-agent-mcp"])
) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
# 列出可用工具
tools = await session.list_tools()
print(tools)
# 调用upload_file工具
result = await session.call_tool("upload_file", {"file": "/path/to/file"})
print(result)
asyncio.run(main())
要添加一个持久客户端,请在你的claude_desktop_config.json或mcp.json文件中添加以下内容:
{
"mcpServers": {
"ifly-spark-agent-mcp": {
"command": "uv",
"args": [
"--directory",
"/path/to/ifly-spark-agent-mcp",
"run",
"ifly-spark-agent-mcp"
],
"env": {
"IFLY_SPARK_AGENT_BASE_URL": "xxxx",
"IFLY_SPARK_AGENT_APP_ID": "xxxx",
"IFLY_SPARK_AGENT_APP_SECRET": "xxxx"
}
}
}
}
{
"mcpServers": {
"ifly-spark-agent-mcp": {
"command": "uvx",
"args": [
"--from",
"git+https://github.com/iflytek/ifly-spark-agent-mcp",
"ifly-spark-agent-mcp"
],
"env": {
"IFLY_SPARK_AGENT_BASE_URL": "xxxx",
"IFLY_SPARK_AGENT_APP_ID": "xxxx",
"IFLY_SPARK_AGENT_APP_SECRET": "xxxx"
}
}
}
}