Python AI MCP Agent
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Python AI MCP AgentWhy is device ABC123 performing slowly?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Python AI MCP Agent
A FastAPI device-support chat application. A supervisor routes actionable requests into predefined skills, retains browser-session context, calls the permitted Model Context Protocol (MCP) tools, and uses the OpenAI Responses API to generate answers.
Architecture
Browser chat message
|
v
FastAPI application
- load browser session
|
v
Supervisor
- select a skill only for a clear support intent
- retain pending workflow and device serial context
- expose only allowed MCP tools
|
v
MCP client (stdio)
|
v
MCP server
- resolve_device_reference
- get_device
- get_device_metrics
- check_provisioning_statusThe backend owns the skill registry. A skill supplies instructions and a tool allowlist, so the model operates inside the selected workflow boundary.
Related MCP server: Connhex MCP Server
Supervisor Graph
The supervisor is represented as graph nodes and conditional edges in ai_backend.py. It makes the workflow explicit while keeping the implementation lightweight.
flowchart TD
receive[Receive message] --> select[Select skill]
select -->|No active skill| out[Out-of-scope reply]
select -->|Active skill| resolve[Resolve device]
resolve -->|Device missing| ask[Ask for serial number]
resolve -->|Device resolved| execute[Execute skill tools]
execute --> reply[Return answer]
ask --> receiveAn active skill can be a newly selected intent or a pending workflow from an earlier message. That edge lets a serial-only reply such as halalfood complete an earlier performance request.
Predefined Skills
Skill | Selected for | Permitted tools |
| Requests containing |
|
| Requests containing |
|
| Requests containing |
|
Greetings and unclear messages, such as Hi, do not select a skill or expose MCP tools.
Conversation Memory
Each browser receives an independent session cookie. The server keeps the session's OpenAI response ID, last resolved device serial, and any unfinished workflow.
For example, the supervisor remembers that the second message completes the first request:
You: Check the performance.
AI: Please provide the device serial number.
You: halalfood
AI: [retrieves and summarizes halalfood performance metrics]When a user supplies a serial-only reply, the supervisor reuses the pending skill, resolves the serial through the device inventory, and completes the requested operation. A new explicit request replaces the pending workflow.
LangGraph Workflow
The FastAPI application runs each message through an executable LangGraph state graph in workflow.py:
flowchart TD
A[Select skill] -->|No support intent| B[Out of scope reply]
A -->|Support intent or pending skill| C[Resolve device]
C -->|Serial unavailable| D[Ask for device serial]
C -->|Serial resolved| E[Execute skill tools]
B --> F[End]
D --> F
E --> FThe execute_skill node filters MCP tools against the selected skill's allowlist before calling the model.
Prerequisites
Python 3.12 or later
An OpenAI API key
Setup
Create and activate a virtual environment in PowerShell:
python -m venv venv
.\venv\Scripts\Activate.ps1Install the dependencies:
pip install -r requirements.txtCreate a .env file in the project root:
OPENAI_API_KEY=your_openai_api_keyTerminal Chat
With the virtual environment active:
python .\ai_backend.pyThe program starts mcp_server.py automatically using the same Python interpreter and starts an interactive terminal chat:
You: Why is device ABC123 performing slowly?Browser Chat
Start the FastAPI application:
uvicorn web_app:app --reloadOpen http://127.0.0.1:8000 in a browser. Each browser receives a separate session cookie, so one user's conversation state cannot conflict with another user's session.
Sample Questions
Show me the historical metrics for device ABC123 for the last 3 days.Is device ABC123 provisioned?Why is device ABC123 performing slowly?Check the performance.halalfoodMCP Tools
The MCP server currently returns mock device data:
Tool | Inputs | Result |
|
| Finds a registered serial number mentioned in the request |
|
| Device model and current status |
|
| Historical latency metrics |
|
| Provisioning status |
Logging
The application logs the full workflow to the terminal: MCP server startup, device resolution, selected skill, permitted tools, model response rounds, tool arguments and results, and request durations.
The default log level is INFO. Enable additional library diagnostics for the current PowerShell session with:
$env:LOG_LEVEL="DEBUG"
uvicorn web_app:app --reloadNotes
This project uses MCP 2.x and imports
MCPServerfrommcp.server.mcp_server.pycommunicates over stdio; do not add ordinaryprint()calls to that server because stdout is reserved for the MCP protocol.Chat sessions are held in the FastAPI process memory. They reset when the server restarts; use Redis or a database for persistent production sessions.
This server cannot be deployed
Maintenance
Related MCP Connectors
Memory for deep conversational context across any platform
Deploy, monitor, and manage your OpenClaw AI assistants via natural language.
Interact with the Stitch API using natural language commands.
List datasets, schemas, run APL queries, and use prompts for exploration, anomalies, and monitoring.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables interactive Kubernetes cluster monitoring and troubleshooting through natural language queries. Users can diagnose pod issues, check service status, and investigate cluster problems using conversational AI.-
- AlicenseBqualityBmaintenanceEnables natural language interaction with Connhex IoT platform APIs for managing devices, telemetry, rules, and resources via MCP tools.301MIT
- FlicenseAqualityDmaintenanceEnables natural language interaction with industrial IoT devices using Sparkplug B, allowing users to query real-time data, analyze historical metrics, and monitor device status.49-
- FlicenseNot gradedqualityDmaintenanceEnables natural language management of apps, services, resources, attributes, and data via the Dimetrics API with full CRUD operations and advanced filtering.-