Skip to main content
Glama

Wikidata MCP Server

by zzaebok
client.py1.33 kB
import os from mcp import ClientSession, StdioServerParameters from mcp.client.stdio import stdio_client from langchain_mcp_adapters.tools import load_mcp_tools from langgraph.prebuilt import create_react_agent from langchain_openai import ChatOpenAI os.environ["OPENAI_API_KEY"] = "your-api-key" model = ChatOpenAI(model="gpt-4o") server_py = os.path.join(os.path.dirname(os.path.abspath(__file__)), "server.py") server_params = StdioServerParameters( command="python", args=[server_py], ) async def main(): async with stdio_client(server_params) as (read, write): async with ClientSession(read, write) as session: # Initialize the connection await session.initialize() # Get tools tools = await load_mcp_tools(session) # Create and run the agent agent = create_react_agent( model, tools, prompt="You are a helpful assistant. Answer the user's questions based on Wikidata.", ) agent_response = await agent.ainvoke( { "messages": "Can you recommend me a movie directed by Bong Joonho?", } ) print(agent_response) if __name__ == "__main__": import asyncio asyncio.run(main())

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/zzaebok/mcp-wikidata'

If you have feedback or need assistance with the MCP directory API, please join our Discord server