Skip to content

Conversation

@mr-brobot
Copy link
Contributor

@mr-brobot mr-brobot commented Mar 3, 2025

details in #11

any feedback welcome, including nits :)

usage example:

# math_server.py
from mcp.server.fastmcp import FastMCP

mcp = FastMCP("Math")

@mcp.tool()
def add(a: int, b: int) -> int:
    """Add two numbers"""
    return a + b

@mcp.tool()
def multiply(a: int, b: int) -> int:
    """Multiply two numbers"""
    return a * b

@mcp.prompt()
def quiz() -> str:
    return "what's (3 + 5) x 12?"

if __name__ == "__main__":
    mcp.run(transport="stdio")
# Create server parameters for stdio connection
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
model = ChatOpenAI(model="gpt-4o")

server_params = StdioServerParameters(
    command="python",
    # Make sure to update to the full absolute path to your math_server.py file
    args=["/path/to/math_server.py"],
)

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)

        # Get prompt
        messages = await load_mcp_prompt(session, "quiz")

        # Create and run the agent
        agent = create_react_agent(model, tools)
        agent_response = await agent.ainvoke(messages)

Copy link

@vbarda vbarda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding -- looks good overall! Added a few small comments - could you add usage example to the PR description?

@mr-brobot mr-brobot changed the title support loading txt & img prompts support loading text prompts Mar 13, 2025
@mr-brobot
Copy link
Contributor Author

@vbarda thanks for the feedback. i think i addressed everything. lmk if there's anything else i can do to help

mr-brobot and others added 3 commits March 13, 2025 11:13
@vbarda
Copy link

vbarda commented Mar 15, 2025

Thank you!

@vbarda vbarda merged commit ac27f57 into langchain-ai:main Mar 15, 2025
3 checks passed
ssmails pushed a commit to ssmails/langchain-mcp-adapters that referenced this pull request May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants