fledge-ai-orchestrator
Facilitates the integration of Fledge operational capabilities with Cursor AI reasoning engine, enabling intuitive, natural language interfacing for accessing telemetry, managing system operations, and generating associated visualization artifacts.
Author

Krupalp525
Quick Info
Actions
Tags
Fledge AI Interaction Gateway
This document details the Model Context Protocol (MCP) intermediary, designed to bridge Fledge infrastructure components with the Cursor AI cognitive engine, allowing instruction execution via conversational prompts.
Necessary Preconditions
- A functional Fledge deployment, either local or reachable via its REST interface (default target:
http://localhost:8081). - Installation of the Cursor AI environment.
- Python runtime environment, version 3.8 or newer.
Deployment Procedure
- Obtain the source repository:
git clone https://github.com/Krupalp525/fledge-mcp.git
cd fledge-mcp
- Establish required dependencies:
pip install -r requirements.txt
Server Initialization Sequence
- Ensure the upstream Fledge data acquisition service is active:
fledge start
- Launch the primary MCP service endpoint:
python mcp_server.py
For deployments necessitating secure endpoint access via token validation:
python secure_mcp_server.py
- Confirm operational status by querying the readiness probe:
curl http://localhost:8082/health
Successful response should yield: "Fledge MCP Server is running"
Cursor AI Configuration
- Navigate to Cursor's configuration menu: Settings > MCP Servers.
- Initiate the addition of a new connection profile:
- Endpoint URL:
http://localhost:8082/tools -
Tool Manifest File: Specify the path to the included
tools.jsonor its local location. -
If utilizing the secured variant, configure the request header named "X-API-Key" utilizing the secret token documented in the
api_key.txtfile generated upon secure server startup. -
Verification Test: Engage the Composer interface (Ctrl+I) within Cursor and input a directive like, "Ascertain Fledge API accessibility." The system should trigger the
validate_api_connectiontool invocation.
Exposed Toolset Catalog
Data Acquisition & Administration
- get_sensor_data: Retrieve sensor readings, supporting temporal boundary definition and result quantity capping.
- list_sensors: Enumerate all registered sensor devices within Fledge.
- ingest_test_data: Inject synthetic data payloads into Fledge, optionally specifying batch size.
System Component Management
- get_service_status: Report on the operational state of all constituent Fledge processes.
- start_stop_service: Command the initiation or termination of a specific service type.
- update_config: Modify configuration settings persisting within the Fledge registry.
Presentation Layer Artifact Generation
- generate_ui_component: Produce React code artifacts suitable for visualizing Fledge metrics.
- fetch_sample_frontend: Obtain boilerplate frontend templates compatible with various presentation frameworks.
- suggest_ui_improvements: Leverage AI analysis to propose enhancements for existing user interface code.
Real-Time Telemetry Streams
- subscribe_to_sensor: Establish a persistent link for receiving asynchronous updates from specified sensors.
- get_latest_reading: Fetch the most recent measured value for a designated sensor identifier.
Diagnostic and Integrity Checks
- validate_api_connection: Perform a connectivity check against the primary Fledge interface.
- simulate_frontend_request: Execute simulated HTTP interactions to benchmark API behavior.
Metadata Retrieval and Schema Inspection
- get_api_schema: Obtain descriptive metadata regarding accessible Fledge API routes.
- list_plugins: List all installed Fledge extension modules.
Advanced Synthetic Data Generation
- generate_mock_data: Create artificially generated, contextually relevant sensor datasets for validation scenarios.
API Execution Verification
Execute the accompanying verification scripts to test server functionality:
# Standard unsecured endpoint test
python test_mcp.py
# Secured endpoint test requiring key management
python test_secure_mcp.py
Security Protocols
The hardened server variant (secure_mcp_server.py) enforces authentication via an API key:
- The initial invocation generates a unique secret key stored in
api_key.txt. - All subsequent API calls mandate the inclusion of this key within the
X-API-Keyrequest header. - The
/healthendpoint remains publicly accessible without token validation.
Sample HTTP Tool Invocation (POST to /tools)
# Verify connectivity
curl -X POST -H "Content-Type: application/json" -d '{"name": "validate_api_connection"}' http://localhost:8082/tools
# Request synthetic data generation
curl -X POST -H "Content-Type: application/json" -d '{"name": "generate_mock_data", "parameters": {"sensor_id": "temp1", "count": 5}}' http://localhost:8082/tools
# Request dynamic UI component generation
curl -X POST -H "Content-Type: application/json" -d '{"name": "generate_ui_component", "parameters": {"component_type": "chart", "sensor_id": "temp1"}}' http://localhost:8082/tools
# Secure server invocation requires key header
curl -X POST -H "Content-Type: application/json" -H "X-API-Key: YOUR_API_KEY" -d '{"name": "list_sensors"}' http://localhost:8082/tools
System Expansion Guidelines
To integrate novel functionalities:
1. Define the new function's metadata within the tools.json manifest.
2. Implement the corresponding handler logic within both mcp_server.py and secure_mcp_server.py files.
Production Deployment Considerations
For enterprise-grade deployment environments: - Mandate secure transport (HTTPS/TLS). - Place the service behind a robust intermediary such as Nginx or an equivalent load balancer. - Adopt advanced authorization schemas (e.g., JWT, OAuth 2.0). - Integrate traffic throttling mechanisms to mitigate abuse. - Establish durable persistence mechanisms for managing subscriptions state.
Deployment on Smithery.ai Platform
The Fledge MCP Server architecture is compatible with Smithery.ai for scaling and high availability:
- Prerequisites Checklist
- Docker runtime installed.
- Active Smithery.ai subscription.
-
Local installation of the Smithery Command Line Interface (CLI).
-
Image Building and Distribution ```bash # Create the executable Docker image docker build -t fledge-mcp .
# Initiate deployment workflow to the platform smithery deploy ```
- Configuration Blueprint (
smithery.json) This file dictates runtime parameters: - WebSocket communication secured on port 8082.
- Parameterizable URL for the target Fledge API.
- Tool definitions catalog and their accepted parameter structures.
-
Connection timeout settings.
-
Environment Variables Setup Configure the following secrets/settings within the Smithery.ai portal:
FLEDGE_API_URL: The accessible endpoint address for the Fledge instance.-
API_KEY: The required secret credential if operating in authentication mode. -
Operational Status Check Confirm successful platform instantiation:
bash smithery status fledge-mcp -
Performance Oversight Utilize the Smithery.ai control panel for ongoing monitoring:
- Real-time log stream access.
- Visualization of performance benchmarks.
- Error tracing and alerting.
-
Resource consumption tracking (CPU, memory).
-
Updating the Service To roll out new iterations: ```bash # Rebuild the container artifact docker build -t fledge-mcp .
# Push the updated version to the cluster smithery deploy --update ```
JSON-RPC 2.0 Protocol Specification
The server adheres to the JSON-RPC 2.0 specification, typically utilizing WebSocket transport for tool invocation. Supported remote procedure calls (RPCs) include:
-
initialize Request Payload Example:
json { "jsonrpc": "2.0", "method": "initialize", "params": {}, "id": "1" }Expected Successful Response Structure:json { "jsonrpc": "2.0", "result": { "serverInfo": { "name": "fledge-mcp", "version": "1.0.0", "description": "Fledge Model Context Protocol (MCP) Server", "vendor": "Fledge", "capabilities": { "tools": true, "streaming": true, "authentication": "api_key" } }, "configSchema": { "type": "object", "properties": { "fledge_api_url": { "type": "string", "description": "Fledge API URL", "default": "http://localhost:8081/fledge" } } } }, "id": "1" } -
tools/list Request Payload Example:
json { "jsonrpc": "2.0", "method": "tools/list", "params": {}, "id": "2" }Response: Delivers a comprehensive manifest detailing all functions and their input parameters. -
tools/call Request Payload Example (Executing a specific function):
json { "jsonrpc": "2.0", "method": "tools/call", "params": { "name": "get_sensor_data", "parameters": { "sensor_id": "temp1", "limit": 10 } }, "id": "3" }
Error Code Mapping
Standard JSON-RPC 2.0 error specifications are observed for signaling issues:
- -32700: Denotes a structural parsing failure in the incoming message payload.
- -32600: Invalid Request structure.
- -32601: The requested method name does not correspond to an implemented function.
- -32602: Input parameters provided do not match the function signature requirements.
- -32000: General internal server execution fault.
