Skip to content

mcp module not found #24

@whoami02

Description

@whoami02

Facing issue -
Traceback (most recent call last):
File "D:\dev\exp\agentic\langgraph\server.py", line 1, in
from mcp.server.fastmcp import FastMCP
ModuleNotFoundError: No module named 'mcp'

added my server.py and client file for reference.
langchain_mcp_adapter version - 0.0.5
langgraph version 0.3.18

server.py

from chatbot_agentic import ToolOrientedRAGChatbot

chatbot = ToolOrientedRAGChatbot()
mcp = FastMCP("chatbot")

@mcp.tool()
def process_query(query: str) -> str:
    return chatbot.process_query(query)

if __name__ == "__main__":
    mcp.run(transport="stdio")

client

import asyncio
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_ollama import ChatOllama
from langchain_core.messages import HumanMessage

async def main():
    model = ChatOllama(model="qwen2.5-coder", temperature=0.2)
    
    server_params = StdioServerParameters(
        command="python",
        args=["server.py"]
    )
    
    async with stdio_client(server_params) as (read, write):
        async with ClientSession(read, write) as session:
            await session.initialize()
            
            tools = await load_mcp_tools(session)
            agent = create_react_agent(model, tools)
            query = HumanMessage(content=str(input("Enter your query: ")))
            
            response = await agent.ainvoke({"messages": [query]})
            
            final_message = response["messages"][-1].content
            print(final_message)
    
if __name__ == "__main__":
    asyncio.run(main())

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions