Skip to content

feat: add MCP server for AI agent device discovery#1410

Open
jajajhhz wants to merge 5 commits intomainfrom
feat/shifumcp
Open

feat: add MCP server for AI agent device discovery#1410
jajajhhz wants to merge 5 commits intomainfrom
feat/shifumcp

Conversation

@jajajhhz
Copy link
Copy Markdown
Collaborator

Summary

  • MCP Server (cmd/shifu-mcp-server/) — Streamable HTTP server exposing list_devices and get_device_desc tools for AI coding agents to discover IoT devices and understand their interaction contracts
  • Device API library (pkg/deviceapi/) — reusable Go library for EdgeDevice CR → DeviceShifu Service/ConfigMap resolution, consumable by shifuctl and other tools
  • CRD extensions — two new optional fields on EdgeDeviceSpec (description, connectionInfo) and three on DeviceShifuInstruction (description, readWrite, safe), fully backward-compatible
  • Example manifests — MQTT robot arm, NATS sensor array, HTTP thermometer with full MCP metadata per spec §4.4
  • 22 tests — unit tests, in-memory transport tests, and E2E tests over real Streamable HTTP covering all 3 spec devices, graceful degradation, and mixed-protocol workflows

Implements shifu_mcp_spec.md.

Key design decisions

  • Protocol-agnostic — uses free-form markdown description fields instead of typed httpSpec/mqttSpec structs; the AI agent reads prose perfectly
  • Two structured hints per interaction: readWrite (R/W/RW) and safe (bool) for safety classification
  • Stateless — all device info read live from K8s API, no caching
  • Graceful degradation — existing EdgeDevice CRs and ConfigMaps without new fields work unchanged

Test plan

  • go test ./pkg/deviceapi/... — 9 tests (API + ConfigMap parsing)
  • go test ./pkg/mcp/server/... — 13 tests (unit + E2E over Streamable HTTP)
  • Verified against live K3s cluster with all 3 spec example devices
  • Verified MCP integration with Claude Code (claude mcp add shifu)
  • CI (make test) will run all tests automatically

🤖 Generated with Claude Code

Implement the Shifu MCP Server as specified in docs/spec/shifu_mcp_spec.md.
This provides a development-time knowledge layer that lets AI coding agents
(Claude Code, Cursor, etc.) discover IoT devices and understand their
interaction contracts to generate correct integration code.

Changes:
- Extend EdgeDevice CRD with optional `description` and `connectionInfo` fields
- Extend DeviceShifuInstruction with `description`, `readWrite`, and `safe` fields
- Add `pkg/deviceapi/` — reusable device resolution and API library
- Add `pkg/mcp/server/` — MCP adapter with list_devices and get_device_desc tools
- Add `cmd/shifu-mcp-server/` — entry point with Streamable HTTP transport
- Add Dockerfile and example manifests for MQTT, NATS, and HTTP devices
- Add comprehensive E2E tests covering all 3 spec example devices

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 12, 2026

Codecov Report

❌ Patch coverage is 76.56250% with 45 lines in your changes missing coverage. Please review.
✅ Project coverage is 36.66%. Comparing base (a358b84) to head (e8db27b).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/mcp/server/server.go 76.00% 14 Missing and 4 partials ⚠️
pkg/deviceapi/api.go 83.05% 6 Missing and 4 partials ⚠️
pkg/k8s/api/v1alpha1/zz_generated.deepcopy.go 0.00% 8 Missing ⚠️
pkg/deviceapi/resolver.go 79.41% 4 Missing and 3 partials ⚠️
pkg/deviceapi/configmap.go 87.50% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1410      +/-   ##
==========================================
+ Coverage   34.81%   36.66%   +1.85%     
==========================================
  Files          54       58       +4     
  Lines        4027     4219     +192     
==========================================
+ Hits         1402     1547     +145     
- Misses       2479     2514      +35     
- Partials      146      158      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

jajajhhz and others added 4 commits March 12, 2026 17:17
Adds a standalone install manifest that deploys the Shifu MCP Server
on top of an existing Shifu installation. Includes RBAC for ConfigMap
read access, a Deployment using the controller SA, and a LoadBalancer
Service exposing port 8443.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fixes golangci-lint unused function error.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@tomqin93 tomqin93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jajajhhz added 2 comments

Comment on lines +48 to +59
connectionInfo:
description: ConnectionInfo is free-form markdown describing how apps
connect to the DeviceShifu service.
type: string
customMetadata:
additionalProperties:
type: string
type: object
description:
description: Description is a free-form markdown description of the
device.
type: string
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to regenerate installation script to reflect these two fields

Comment on lines +49 to +53
dep := &deployments.Items[i]
if matchesDevice(dep, deviceName) {
info := &deviceDeploymentInfo{
ServiceName: dep.Name + "." + deviceShifuNamespace + ".svc.cluster.local",
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name of the deployment and service may not be the same. need a way to link them

@tomqin93
Copy link
Copy Markdown
Contributor

@jajajhhz let's add an end 2 end testing for this feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants