Discover Awesome MCP Servers

Extend your agent with 84,517 capabilities via MCP servers.

All84,517
MCP to LangChain/LangGraph Adapter

MCP to LangChain/LangGraph Adapter

Okay, I understand. You want a Python adapter that takes tools designed for an MCP (presumably Minecraft Protocol) server and makes them usable as tools within the Langchain framework. Here's a conceptual outline and a code snippet to get you started. This is a basic example and will need to be adapted to your specific MCP server tools and Langchain setup. **Conceptual Outline** 1. **Understand MCP Server Tools:** You need to know how to interact with your MCP server tools. This likely involves sending commands over a network connection (e.g., TCP socket) and parsing the responses. You'll need to define the specific commands each tool accepts and the format of the data it returns. 2. **Langchain Tool Interface:** Langchain tools have a specific interface. They need a `name`, a `description`, and a `_run` method (or `arun` for asynchronous execution) that takes a string as input and returns a string as output. 3. **Adapter Class:** Create a Python class that inherits from `langchain.tools.BaseTool`. This class will: * Initialize with the necessary connection details for your MCP server. * Implement the `_run` method to: * Connect to the MCP server. * Format the input string into a command suitable for the MCP server tool. * Send the command to the server. * Receive the response from the server. * Parse the response. * Return the parsed response as a string. * Define the `name` and `description` attributes for the tool. **Code Snippet (Basic Example)** ```python from langchain.tools import BaseTool import socket import json # Assuming your MCP server uses JSON for communication class MCPServerTool(BaseTool): """Tool for interacting with an MCP server.""" name: str = "mcp_server_tool" # Replace with a more descriptive name description: str = ( "Useful for interacting with a Minecraft server. " "Input should be a JSON string containing the 'command' and any necessary 'arguments'." ) host: str = "localhost" # Replace with your MCP server's host port: int = 25565 # Replace with your MCP server's port def _run(self, query: str) -> str: """Use the tool.""" try: query_json = json.loads(query) command = query_json.get("command") arguments = query_json.get("arguments", {}) # Default to empty dict if no arguments if not command: return "Error: 'command' key missing in the input JSON." # Format the command for the MCP server (adjust as needed) mcp_command = self._format_mcp_command(command, arguments) # Connect to the MCP server with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect((self.host, self.port)) s.sendall(mcp_command.encode()) # Encode to bytes # Receive the response (adjust buffer size as needed) response = s.recv(1024).decode() # Decode from bytes # Parse the response (assuming JSON) try: response_json = json.loads(response) return json.dumps(response_json) # Return as JSON string except json.JSONDecodeError: return f"MCP Server Response: {response}" # Return raw response if not JSON except json.JSONDecodeError: return "Error: Invalid JSON input." except Exception as e: return f"Error: {e}" async def _arun(self, query: str) -> str: """Use the tool asynchronously.""" raise NotImplementedError("This tool does not support asynchronous execution.") def _format_mcp_command(self, command: str, arguments: dict) -> str: """Formats the command for the MCP server. Adjust this based on your server's protocol.""" # Example: Assuming the server expects commands like "command arg1=value1 arg2=value2" command_string = command for key, value in arguments.items(): command_string += f" {key}={value}" return command_string ``` **How to Use** 1. **Replace Placeholders:** Fill in the `host`, `port`, `name`, and `description` attributes with the correct values for your MCP server and tool. 2. **Implement `_format_mcp_command`:** This is crucial. This method *must* format the input `command` and `arguments` into the exact format that your MCP server expects. This will vary depending on your server's protocol. 3. **Adjust Socket Communication:** The `socket` code might need adjustments. Consider: * **Buffering:** The `recv(1024)` call receives up to 1024 bytes. If your server sends larger responses, you'll need to receive in a loop until you have the complete response. * **Encoding:** Make sure you're using the correct encoding (e.g., UTF-8) for both sending and receiving data. * **Error Handling:** Add more robust error handling (e.g., timeouts, connection errors). 4. **Parse Responses:** The code assumes the server returns JSON. If it returns a different format, you'll need to change the parsing logic accordingly. 5. **Add to Langchain:** Instantiate the `MCPServerTool` and add it to your Langchain agent's tools list. ```python # Example of adding the tool to a Langchain agent from langchain.agents import initialize_agent from langchain.llms import OpenAI # Or your preferred LLM # Replace with your OpenAI API key openai_api_key = "YOUR_OPENAI_API_KEY" llm = OpenAI(temperature=0, openai_api_key=openai_api_key) mcp_tool = MCPServerTool() tools = [mcp_tool] agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True) # Example usage prompt = """ What is the current time on the Minecraft server? The input to this tool should be a json string with the command and arguments. """ # The agent will call the tool with an input like: # '{"command": "get_time", "arguments": {}}' # Assuming your _format_mcp_command formats it correctly. agent.run(prompt) ``` **Important Considerations** * **Security:** Be extremely careful about security. Never expose your MCP server directly to the internet without proper security measures. Sanitize all input to prevent command injection vulnerabilities. Consider using authentication and authorization. * **Error Handling:** Implement robust error handling to catch exceptions and provide informative error messages. * **Asynchronous Execution:** If you need asynchronous execution, you'll need to use `asyncio` and asynchronous socket operations. The `_arun` method in the example raises `NotImplementedError`. * **MCP Server Protocol:** The most important part is understanding and correctly implementing the communication protocol with your MCP server. Consult your server's documentation or source code for details. * **Langchain Agent Type:** The `zero-shot-react-description` agent is a good starting point, but you might need to experiment with different agent types to find one that works best for your use case. This comprehensive response should give you a solid foundation for building your MCP server tool adapter for Langchain. Remember to adapt the code to your specific needs and prioritize security. Good luck!

Blender MCP Server

Blender MCP Server

Exposes 50+ Blender tools (object manipulation, materials, animation, etc.) via MCP for AI-driven 3D workflows and automation.

MCP Yandex Voice

MCP Yandex Voice

MCP server for Cursor that generates text responses via Yandex GPT and converts them to speech using Yandex SpeechKit TTS, enabling voice replies to user messages.

TradingView MCP Bridge

TradingView MCP Bridge

Connects AI assistants to your local TradingView Desktop app via Chrome DevTools Protocol for chart analysis, Pine Script development, and workflow automation while keeping all data local.

gx3-mcp-server

gx3-mcp-server

Provides read-only analysis of Mitsubishi GX Works3 PLC projects via MCP, enabling device tracing, cross-referencing, ladder inspection, linting, and report generation without modifying source projects.

discord-mcp

discord-mcp

MCP server for interacting with Discord via REST API, enabling guild, channel, and message operations using a bot token.

TreasuryOS

TreasuryOS

An AI-powered treasury management MCP server that enables users to perform commercial banking analysis, including cash flow forecasting, idle cash detection, and debt covenant monitoring. It provides tools to surface financial insights and optimize working capital through automated processing of bank and transaction data.

futu-opend-mcp

futu-opend-mcp

Read-only MCP server that exposes Futu OpenD's investment-research quote APIs (stocks, options, futures, financials, news, etc.) as MCP tools, leveraging an already-running OpenD gateway with no separate authentication.

diagram-mcp

diagram-mcp

Renders Mermaid diagrams and Plotly charts to SVG, PNG, or PDF formats via the Model Context Protocol.

us-gov-data-mcp

us-gov-data-mcp

MCP server for querying US federal contracts and public company financial data from USAspending and SEC EDGAR. Enables searching expiring contracts, screening companies by metrics, and retrieving financial histories.

sophtron-mcp

sophtron-mcp

Query bank accounts, credit cards, and transactions via Sophtron's financial data API. Works with Claude Desktop and any MCP-compatible client.

phison-mail-mcp

phison-mail-mcp

Enables AI models to send, receive, search, and manage emails via SMTP/IMAP, including support for attachments, contacts, and advanced search.

SSH MCP Server

SSH MCP Server

Enables AI apps to connect to remote servers via SSH, SFTP, and tunnels.

seeany-sun-mcp

seeany-sun-mcp

MCP server for SeeAny Sun enabling product image generation, smart creation, task polling, and download via natural language, with demo mode for offline simulation.

cysic-mcp

cysic-mcp

Exposes the Cysic AI model to any MCP client over stdio, with server-side session memory and a tone-rewriting tool.

Zulip MCP Server

Zulip MCP Server

A Model Context Protocol server that enables AI assistants to interact with Zulip workspaces by exposing REST API capabilities as tools for message operations, channel management, and user interactions.

Open Library MCP Server

Open Library MCP Server

Connects AI assistants to the Open Library API for searching books and authors, retrieving metadata, and comparing works.

oura-ring-mcp

oura-ring-mcp

Provides natural-language access to Oura health data through Claude, with a local SQLite mirror and MCP tools for analyzing patterns with personal annotations.

specrun

specrun

MCP server that turns OpenAPI specs into tools and calls API

OpenAlex MCP Server

OpenAlex MCP Server

Provides academic research tools via the OpenAlex API, enabling searches for papers, authors, concepts, institutions, and citation analysis.

spudcoach

spudcoach

A deterministic theorycrafter for the game Brotato, enabling natural language queries about weapons, items, characters, DPS calculations, and build evaluation.

Prompt Refiner MCP Server

Prompt Refiner MCP Server

Helps systematically refine vague ideas into well-structured prompts through guided clarification and export templates.

AWO MCP Server

AWO MCP Server

Exposes processed AWO facility, address, service, and provider datasets to AI assistants. Enables natural-language queries for counting, searching, detailing, comparing, and analyzing facilities.

capcut-mcp

capcut-mcp

An MCP server that reads and builds CapCut projects locally, enabling natural language queries about project contents, missing media, and creation of new edits including beat-synced cuts.

Online Boutique AI Assistant MCP Server

Online Boutique AI Assistant MCP Server

MCP server for Online Boutique AI Assistant that exposes 18 e-commerce microservice functions via the Model Context Protocol, enabling any MCP client to manage products, carts, checkout, payments, and shipping.

DREAMVFIA Windows MCP

DREAMVFIA Windows MCP

A lean local Windows automation server providing tools for mouse and keyboard control, screenshot capture, and process management. It enables programmatic interaction with the Windows desktop environment through the Model Context Protocol.

brainiall-mcp-server

brainiall-mcp-server

AI-powered speech tools by Brainiall: pronunciation assessment with phoneme-level feedback, speech-to-text with language detection, and text-to-speech with multiple voices.

Company API MCP Server

Company API MCP Server

Exposes internal company services as LLM-callable MCP tools, enabling AI agents to perform business operations like customer management, order processing, and support ticketing through natural language.

WordPress MCP Server

WordPress MCP Server

Enables AI assistants to interact with WordPress sites through the REST API. Supports multiple WordPress sites with secure authentication, enabling content management, post operations, and site configuration through natural language.

jira-mcp-server

jira-mcp-server

Integrates Jira tickets with GitHub Copilot Chat, fetching ticket details, linked tickets, and metadata to enhance context for AI-driven code suggestions.