verify_mcp.py•2.09 kB
#!/usr/bin/env python3
"""
快速验证MCP服务器功能
"""
import asyncio
import json
from mcp.client.stdio import stdio_client
from mcp import ClientSession, StdioServerParameters
async def quick_test():
"""快速测试MCP服务器"""
print("🧪 PubChem MCP Server 快速验证")
print("=" * 40)
server_params = StdioServerParameters(
command='uv',
args=['run', 'pubchem_mcp/mcp_server.py'],
)
try:
async with stdio_client(server_params) as (stdio, write):
async with ClientSession(stdio, write) as session:
await session.initialize()
print("✅ MCP服务器连接成功")
# 测试获取工具列表
tools_response = await session.list_tools()
print(f"📋 可用工具: {len(tools_response.tools)} 个")
# 测试获取化合物信息
print("\n🔬 测试获取 Malachite Green 信息...")
result = await session.call_tool('get_compound_info', {'name': 'Malachite Green'})
data = json.loads(result.content[0].text)
print(f" ✅ CID: {data.get('cid')}")
print(f" ✅ 分子式: {data.get('molecular_formula')}")
print(f" ✅ 分子量: {data.get('molecular_weight')}")
print("\n🎉 MCP服务器功能验证完成!")
print("\n💡 下一步:")
print(" 1. 在Claude Desktop中配置此MCP服务器")
print(" 2. 使用Claude查询化学安全信息")
print(" 3. 运行 'uv run example_usage.py' 查看更多示例")
except Exception as e:
print(f"❌ 错误: {e}")
return False
return True
if __name__ == "__main__":
success = asyncio.run(quick_test())
if success:
print("\n✨ 验证成功!MCP服务器可以正常使用。")
else:
print("\n⚠️ 验证失败,请检查服务器配置。")