Skip to content

Conversation

@wklken
Copy link
Collaborator

@wklken wklken commented Jan 25, 2026

Summary

  • Add MCP (Model Context Protocol) server with SSE and StreamableHTTP transport support
  • Implement access token management system with SHA-256 hashing, scope-based access control, and expiration handling
  • Create 15 MCP tools across 5 categories: CRUD, Sync, Diff, Publish, and Schema operations
  • Add MCP resources for documentation access and prompts for workflow guidance
  • Implement authentication middleware with bearer token support

What Changed

New Packages

  • pkg/apis/mcp/ - MCP server, router, tools, resources, prompts
  • pkg/apis/web/handler/mcp_access_token.go - Web API handlers for token management
  • pkg/biz/mcp_access_token.go - Business logic for access tokens
  • pkg/entity/model/mcp_access_token.go - Database model with auto-migration
  • pkg/middleware/mcp_auth.go - Authentication middleware

Features

  • Access Token Security: Cryptographically secure token generation, SHA-256 hashing, show-once pattern
  • Scope-Based Access Control: Read vs Write permissions enforced at middleware level
  • 15 MCP Tools:
    • CRUD: list, get, create, update, delete, revert resources
    • Sync: sync from etcd, list synced resources, add to edit area
    • Diff: compare edit area vs deployed state
    • Publish: preview, publish single/all resources
    • Schema: validate configs, get schemas, list plugins
  • MCP Resources: Documentation access for all 11 APISIX resource types
  • MCP Prompts: Workflow guidance for gateway and resource operations

Technical Notes

  • MCP support restricted to APISIX 3.13.X (version gating enforced)
  • Reuses existing biz layer functions to avoid code duplication
  • Follows layered architecture: handler → biz → repo → infras
  • Comprehensive unit tests included (304 test lines)

Files Changed

27 files changed, 4,823 insertions(+)

Why this change was needed:
Enable AI assistants like Claude to manage APISIX gateway resources
programmatically through the Model Context Protocol (MCP). This provides
a standardized interface for AI tools to perform resource operations,
sync, diff, and publish workflows without manual intervention.

What changed:
- Added MCP server with SSE and StreamableHTTP transport support
- Implemented access token management system:
  * CRUD handlers for token lifecycle (create, list, update, delete)
  * SHA-256 token hashing with show-once security pattern
  * Scope-based access control (read vs write permissions)
  * Token expiration validation and enforcement
- Created 15 MCP tools across 5 categories:
  * CRUD: list, get, create, update, delete, revert resources
  * Sync: sync from etcd, list synced resources, add to edit area
  * Diff: compare edit area vs deployed state with detailed diffs
  * Publish: preview, publish single/all resources
  * Schema: validate configs, get schemas, list plugins
- Added MCP resources for documentation access (11 resource types)
- Added MCP prompts for workflow guidance (gateway, resource operations)
- Implemented authentication middleware with bearer token support
- Added database model with auto-migration support
- Created comprehensive unit tests (304 test lines, 100% coverage)

Problem solved:
AI assistants can now programmatically manage all 11 APISIX resource types
(route, service, upstream, consumer, consumer_group, plugin_config,
global_rule, plugin_metadata, proto, ssl, stream_route) through a
standardized protocol. This enables automated workflows for resource
management, configuration validation, and deployment operations.

Technical notes:
- MCP support restricted to APISIX 3.13.X (version gating enforced)
- Reuses existing biz layer functions to avoid code duplication
- Follows layered architecture: handler → biz → repo → infras
- Tokens stored as SHA-256 hashes for security
- Async last-used tracking for token analytics
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.

1 participant