{"slug": "day-23-30-expose-tools-with-mcp", "title": "Day 23/30: Expose Tools with MCP", "summary": "A developer detailed the process of building an MCP server to expose tools to AI applications, using a sentiment analysis tool as an example. The team's support bot, powered by LangGraph and MCP, initially struggled with context retention due to the lack of a centralized tooling server. The post provides code examples for defining a tool and setting up a Flask-based MCP server, and highlights the importance of synchronizing tool registration with server configuration.", "body_md": "I still remember the frustration when our team's support bot, powered by LangGraph and MCP, couldn't retain context between user interactions. It was as if the bot had a case of conversational amnesia, forcing users to repeat themselves over and over. We later discovered that the issue stemmed from our lack of a centralized tooling server, making it impossible for the bot to access and leverage external tools in a scalable manner. This experience taught us the importance of building a robust MCP server to expose tools to our AI applications.\n\nIn this post, we'll walk through the process of setting up an MCP server, focusing on exposing a single tool to any MCP-compatible AI app. Let's consider a simple tool that performs sentiment analysis on text input. We want this tool to be accessible from our support bot, allowing it to gauge user sentiment and respond accordingly.\n\nThe first step in building an MCP server is to define the tool and its interface. MCP provides a set of APIs and protocols for tool definition, including the `Tool`\n\nclass and the `MCPTool`\n\ninterface. We'll use these to create our sentiment analysis tool. Here's a simplified example of how we might define this tool in Python:\n\n``` python\nfrom MCP import Tool, MCPTool\n\nclass SentimentAnalysisTool(Tool, MCPTool):\n    def __init__(self):\n        super().__init__()\n        self.name = \"SentimentAnalysis\"\n        self.description = \"Analyzes the sentiment of the input text\"\n\n    def execute(self, input_text):\n        # Simplified sentiment analysis logic for demonstration\n        if \"love\" in input_text or \"great\" in input_text:\n            return \"Positive\"\n        elif \"hate\" in input_text or \"bad\" in input_text:\n            return \"Negative\"\n        else:\n            return \"Neutral\"\n\n# Create an instance of our tool\nsentiment_tool = SentimentAnalysisTool()\n```\n\nNext, we need to set up an MCP server to host our tool. MCP servers can be configured to expose tools over various interfaces, including REST and gRPC. For simplicity, let's use a basic REST server. We'll use Flask, a lightweight Python web framework, to create our server. Here's how we might set it up:\n\n``` python\nfrom flask import Flask, request, jsonify\nfrom MCP import ToolServer\n\napp = Flask(__name__)\n\n# Create an MCP tool server\ntool_server = ToolServer()\n\n# Register our sentiment analysis tool with the server\ntool_server.register_tool(sentiment_tool)\n\n# Define a route for tool execution\n@app.route('/tools/<tool_name>/execute', methods=['POST'])\ndef execute_tool(tool_name):\n    tool = tool_server.get_tool(tool_name)\n    if tool:\n        input_text = request.json['input_text']\n        result = tool.execute(input_text)\n        return jsonify({'result': result})\n    else:\n        return jsonify({'error': 'Tool not found'}), 404\n\nif __name__ == '__main__':\n    app.run(debug=True)\n```\n\nWith our MCP server up and running, our support bot (or any other MCP-compatible AI app) can now access the sentiment analysis tool by sending a POST request to the `/tools/SentimentAnalysis/execute`\n\nendpoint with the text to be analyzed in the request body.\n\nA practical gotcha to watch out for when building MCP servers is ensuring that tool registration and server configuration are properly synchronized. If tools are registered after the server has started, they might not be accessible until the server is restarted. To avoid this, consider implementing a dynamic tool registration mechanism that updates the server's tool list in real-time.\n\nAs we move forward in our agentic AI journey, tomorrow we'll explore more advanced topics in integrating LangGraph and MCP, further enhancing our AI applications' capabilities.", "url": "https://wpnews.pro/news/day-23-30-expose-tools-with-mcp", "canonical_source": "https://dev.to/yashwanth_kasi/day-2330-expose-tools-with-mcp-5ak5", "published_at": "2026-08-02 05:47:08+00:00", "updated_at": "2026-08-02 06:10:38.021312+00:00", "lang": "en", "topics": ["developer-tools", "ai-tools", "ai-infrastructure"], "entities": ["LangGraph", "MCP", "Flask", "SentimentAnalysis"], "alternates": {"html": "https://wpnews.pro/news/day-23-30-expose-tools-with-mcp", "markdown": "https://wpnews.pro/news/day-23-30-expose-tools-with-mcp.md", "text": "https://wpnews.pro/news/day-23-30-expose-tools-with-mcp.txt", "jsonld": "https://wpnews.pro/news/day-23-30-expose-tools-with-mcp.jsonld"}}