Day 23/30: Expose Tools with MCP 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. 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. In 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. The 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 class and the MCPTool interface. We'll use these to create our sentiment analysis tool. Here's a simplified example of how we might define this tool in Python: python from MCP import Tool, MCPTool class SentimentAnalysisTool Tool, MCPTool : def init self : super . init self.name = "SentimentAnalysis" self.description = "Analyzes the sentiment of the input text" def execute self, input text : Simplified sentiment analysis logic for demonstration if "love" in input text or "great" in input text: return "Positive" elif "hate" in input text or "bad" in input text: return "Negative" else: return "Neutral" Create an instance of our tool sentiment tool = SentimentAnalysisTool Next, 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: python from flask import Flask, request, jsonify from MCP import ToolServer app = Flask name Create an MCP tool server tool server = ToolServer Register our sentiment analysis tool with the server tool server.register tool sentiment tool Define a route for tool execution @app.route '/tools/