Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
66c75a4
general structure
Dec 1, 2025
af2be51
fix appium interfaces
Jan 19, 2026
1f41a42
Fix critical bugs and refactor MCP tool registration
Feb 9, 2026
2ce5699
Add interactive element operation tools (12 new MCP tools)
Feb 9, 2026
9d3f3b2
Enhance all MCP tool descriptions with detailed English
Feb 9, 2026
1cdeb1b
Add MCP protocol and tool validation tests
Feb 10, 2026
1b41fb7
feat: update mcp server integration and devicefarm workflow
Mar 12, 2026
cfabd6e
feat: add persistent file logging and detailed execution traces
Mar 15, 2026
c212088
Strengthen startup checks and execution timeout handling
Mar 18, 2026
bc25a00
Expand orchestrator health reporting
Mar 18, 2026
517f6a1
Harden auth paths and add integration coverage
Mar 22, 2026
34d5689
Harden distributed execution and release prep
Mar 22, 2026
a0bd55f
Finalize release checklist and ownership enforcement
Mar 22, 2026
d49913f
Add direct coverage for previously untested packages
Mar 22, 2026
6f01964
Strengthen behavioral coverage for release paths
Mar 22, 2026
cb7531c
Remove A2A-style REST surface
Mar 23, 2026
f841d06
Finish v1.0.0 stabilization fixes
Mar 23, 2026
7a683a9
Add Device Farm remote access session support
Mar 23, 2026
f088dea
Align MCP notification handling
Apr 21, 2026
11f3db0
Add MCP streamable HTTP endpoint
Apr 21, 2026
0cf3db4
Align MCP 2026-07-28 and harden runtime
Aug 6, 2026
4f64fbc
Clean alignment documentation
Aug 6, 2026
f2a40fe
Merge MCP 2026-07-28 alignment into v1
IceMask Aug 6, 2026
251b7f9
Merge v1 into main
Aug 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ All notable changes to this repository are documented in this file.

The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and versions are intended to follow [Semantic Versioning](https://semver.org/).

## [Unreleased]

### Added

- MCP `2026-07-28` stateless request metadata, `server/discover`, modern result decoration, and Streamable HTTP routing headers
- JSON Schema 2020-12 tool validation, deterministic discovery, resource-template separation, and exact JSON-RPC request ID preservation
- Runtime audit recording for authentication, WebSocket credentials, worker lifecycle, and distributed ownership transitions
- Worker capacity admission, execution deduplication, atomic Redis lease operations, and race-focused distributed tests

### Changed

- `tools/call` business and downstream failures now return normal MCP results with sanitized `isError` payloads
- HTTP inputs now use bounded strict JSON decoding, server timeouts, and transport-safe status mappings
- Session cleanup, queue retry, trace terminalization, Appium retry policy, authentication validation, and configuration loading now fail closed
- Public documentation now describes MCP `2026-07-28`, current dependency preflights, and the gateway/distributed runtime boundary

### Fixed

- Prevented stdio logs from corrupting protocol stdout and removed raw backend diagnostics from client-visible errors
- Prevented stale callbacks, duplicate worker execution, capacity races, and non-atomic lease renewal or release
- Preserved retryable session cleanup, trace/session screenshot ownership, DAO not-found distinctions, and cancelled worker waits

## [1.0.0] - 2026-03-24

### Added
Expand Down
90 changes: 90 additions & 0 deletions MCP_2026_07_28_ALIGNMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# MCP 2026-07-28 升级说明

本仓库已按官方 Current 版本 `2026-07-28` 完成核心 server/transport 对齐,并继续兼容 initialize-based legacy 客户端。官方参考:

- [MCP 2026-07-28 Specification](https://modelcontextprotocol.io/specification/2026-07-28)
- [2026-07-28 Changelog](https://modelcontextprotocol.io/specification/2026-07-28/changelog)
- [Versioning and Compatibility](https://modelcontextprotocol.io/specification/2026-07-28/basic/versioning)
- [Streamable HTTP](https://modelcontextprotocol.io/specification/2026-07-28/basic/transports/streamable-http)
- [Server Discovery](https://modelcontextprotocol.io/specification/2026-07-28/server/discover)
- [Base Protocol](https://modelcontextprotocol.io/specification/2026-07-28/basic/index)
- [Resources](https://modelcontextprotocol.io/specification/2026-07-28/server/resources)
- [Tools](https://modelcontextprotocol.io/specification/2026-07-28/server/tools)

## 协议变化摘要

| 变化 | `2025-11-25` 及更早 | `2026-07-28` | 本仓库实现 |
| --- | --- | --- | --- |
| 生命周期 | `initialize` + `notifications/initialized` | 无握手、逐请求无状态 | 双时代兼容 |
| 版本/能力 | 初始化时协商 | 每个 request 的 `params._meta` | 强制验证两个必填 namespaced 字段 |
| 服务发现 | 依赖 initialize capabilities | `server/discover` 为服务端必选 | 已实现并返回全部支持版本 |
| 成功结果 | `resultType` 可缺失 | 每个结果必须声明 `resultType` | 现代结果统一补 `complete` |
| Request ID | 旧集成可能混淆 `null` 与 omitted | 仅 string/integer,且不得为 `null` | 三个 transport 统一保留 presence 并校验类型 |
| 服务身份 | initialize 的 `serverInfo` | 推荐每个 result 的 `_meta` | 现代结果统一补 namespaced `serverInfo` |
| HTTP | POST,可选 GET/SSE 和 session | 仅 POST,无 GET stream/session id | `/mcp` GET 返回 405,POST 无 session 状态 |
| HTTP 镜像头 | 仅协议版本 | 另需 `Mcp-Method`;指定方法需 `Mcp-Name` | 校验缺失、编码和 header/body 一致性 |
| 工具/资源缓存 | 无统一字段 | list/template-list/read 支持 `ttlMs`、`cacheScope` | 目录使用 public,授权相关 resource read 使用 private |
| 资源模板 | 可被旧集成混入 `resources/list` | 参数化 URI 由 `resources/templates/list` 返回 | Modern 分离 concrete resources 与 URI templates,legacy 保持原结果 |
| Tool schema | dialect 行为不统一 | 默认且至少支持 JSON Schema 2020-12 | 显式声明并使用 2020-12 校验器 |
| Tool result | structured object 限制较多 | `structuredContent` 可为任意 JSON | 同时返回 text 与原生 structured JSON |

## 当前支持矩阵

- Modern:`2026-07-28`,通过每个 request 的 `_meta` 选择,无 initialize。
- Legacy:`2025-11-25` 和 `2025-06-18`,继续通过 initialize 选择。
- `server/discover` 返回上述三个版本,顺序为 modern 优先。
- Modern 方法:`server/discover`、`tools/list`、`tools/call`、`resources/list`、`resources/templates/list`、`resources/read`,以及 stdio cancellation 处理。
- Modern `resources/list` 当前返回空 concrete resource 集合;三个参数化 Appium URI 由 `resources/templates/list` 返回。
- Legacy 的 `ping`、`notifications/initialized` 与现有兼容方法保持可用,但在 modern `_meta` 下返回 method not found。
- Modern Streamable HTTP 不接收 client notification;取消正在执行的 HTTP 请求应关闭该请求的响应流,`notifications/cancelled` 仅保留给 stdio。
- `/jsonrpc` 继续作为非标准 compatibility endpoint;标准 MCP HTTP endpoint 是 `/mcp`。

## Modern Request 要求

每个 JSON-RPC request 的 `params._meta` 必须包含:

```json
{
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {}
}
```

`io.modelcontextprotocol/clientInfo` 可选,但建议每次提供。HTTP 同时要求:

- `Content-Type: application/json`
- `Accept: application/json, text/event-stream`
- `MCP-Protocol-Version` 与 body protocol version 一致
- `Mcp-Method` 与 JSON-RPC `method` 一致
- `tools/call`、`resources/read`、`prompts/get` 的 `Mcp-Name` 与 `params.name` / `params.uri` 一致
- 不安全 ASCII、非 ASCII 或首尾空白的 `Mcp-Name` 使用 `=?base64?{Base64}?=` sentinel

关键错误映射:

- Header 缺失、格式错误或与 body 不一致:HTTP 400 / JSON-RPC `-32020`
- Modern 必填 `_meta` 字段缺失:HTTP 400 / JSON-RPC `-32602`
- 请求版本不支持:HTTP 400 / JSON-RPC `-32022`,data 包含 `supported` 和 `requested`
- Modern RPC 未实现:HTTP 404 / JSON-RPC `-32601`
- Resource 不存在或对调用方不可见:JSON-RPC `-32602`;后端读取失败:JSON-RPC `-32603`

## 实现位置

- `internal/gateway/mcp/protocol.go`:版本、逐请求 metadata、discover、现代 result/cache decoration 与标准错误。
- `internal/gateway/jsonrpc/modern.go`:modern/legacy 分类与 modern 方法边界。
- `internal/gateway/mcphttp/handler.go`:双时代 Streamable HTTP、标准头和状态码。
- `internal/gateway/mcp/tools.go`:确定性排序和 JSON Schema 2020-12 预编译校验。
- `internal/gateway/mcp/handler.go`:legacy-compatible 基础结果与 `structuredContent`。

## 验证

```bash
go test ./internal/gateway/mcp ./internal/gateway/jsonrpc ./internal/gateway/mcphttp -count=1
go test ./... -count=1
go vet ./...
```

测试覆盖 modern discovery、逐请求 metadata、unsupported-version retry data、legacy 回归、request ID 校验、HTTP header mismatch、Base64 sentinel、modern 404、HTTP notification rejection、resource/template 分离、resource error codes、结果装饰、确定性 tool ordering,以及 `unevaluatedProperties` 的 JSON Schema 2020-12 行为。

## 非阻塞扩展项

Prompts、subscriptions/listen、sampling、elicitation、MCP Apps、Tasks 等仍是未声明的可选 capability,不影响当前 tools/resources server 对 `2026-07-28` 核心协议的支持。后续增加任何 capability 时,应同时加入 discover capability 声明、逐请求 client capability 检查及对应 conformance tests。
81 changes: 69 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
# Tentacle

Tentacle is a mobile automation gateway that exposes Appium and AWS Device Farm workflows through standard MCP, HTTP JSON-RPC, WebSocket event streaming, and internal gRPC services.
Tentacle is a mobile automation gateway that exposes Appium and AWS Device Farm workflows through standard MCP over `stdio` and Streamable HTTP, HTTP JSON-RPC compatibility, WebSocket event streaming, and internal gRPC services.

It is designed for AI-assisted mobile testing, scripted automation, and browser-based monitoring. The repository ships with embedded validation tools, PostgreSQL migrations, and production-oriented configuration examples so the same codebase can be used for local development, CI, and hosted deployments.

## Highlights

- Standard MCP server for `stdio` clients such as Claude Desktop
- MCP `2026-07-28` stateless server with `2025-11-25` and `2025-06-18` initialization-based compatibility
- Standard MCP transports through `stdio` and Streamable HTTP `POST /mcp`
- HTTP JSON-RPC endpoint for service-to-service integrations
- Deterministic JSON Schema 2020-12 catalog with 26 built-in tools and an `adbShell` kill switch
- Session lifecycle, element actions, gestures, screenshots, health checks, and semantic snapshots
- Browser event streaming through short-lived WebSocket subscription tokens
- AWS Device Farm support for both scheduled test runs and live remote-access Appium sessions
- PostgreSQL, Redis, and S3-backed persistence for traces, events, and artifacts

## Quick Start

### Prerequisites And Build

Local development uses the Go version declared in `go.mod` and requires PostgreSQL, Redis, and an existing S3 or S3-compatible bucket. Gateway startup checks those three dependencies before listening. Appium 2 is required when a mobile session is created, but not for protocol discovery or health inspection.

```bash
cp config.example.yaml config.yaml
mkdir -p bin
go build -o ./bin/gateway ./cmd/gateway
```

Update `config.yaml` with reachable PostgreSQL, Redis, and S3 settings before starting the binary. The S3 identity needs `HeadBucket` access at startup and object access for screenshot artifacts.

### Claude Desktop

Add Tentacle as an MCP server in your Claude Desktop configuration:
Expand All @@ -23,7 +37,7 @@ Add Tentacle as an MCP server in your Claude Desktop configuration:
{
"mcpServers": {
"tentacle": {
"command": "/absolute/path/to/gateway",
"command": "/absolute/path/to/repository/bin/gateway",
"args": ["--stdio", "--config", "/absolute/path/to/config.yaml"]
}
}
Expand All @@ -35,27 +49,50 @@ Common configuration file locations:
- macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
- Windows: `%APPDATA%\\Claude\\claude_desktop_config.json`

### HTTP JSON-RPC
### MCP Streamable HTTP

Start the gateway:

```bash
./gateway --config config.yaml
./bin/gateway --config config.yaml
```

List the available tools:
Discover the server through the stateless MCP `2026-07-28` endpoint:

```bash
curl -X POST http://localhost:8080/jsonrpc \
curl -X POST http://localhost:8080/mcp \
-H "Accept: application/json, text/event-stream" \
-H "Content-Type: application/json" \
-H "MCP-Protocol-Version: 2026-07-28" \
-H "Mcp-Method: server/discover" \
-d '{
"jsonrpc": "2.0",
"method": "tools/list",
"params": {},
"method": "server/discover",
"params": {
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {},
"io.modelcontextprotocol/clientInfo": {"name": "local-test", "version": "1.0.0"}
}
},
"id": 1
}'
```

Every modern request repeats the namespaced protocol metadata. HTTP requests also mirror the method in `Mcp-Method`; `tools/call` and `resources/read` mirror their target in `Mcp-Name`.

### HTTP JSON-RPC Compatibility

The non-standard `/jsonrpc` endpoint remains available for existing integrations. List the available tools with:

```bash
curl -X POST http://localhost:8080/jsonrpc \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"tools/list","params":{},"id":2}'
```

The local configuration disables authentication. When PAT, OIDC, or HMAC authentication is enabled, supply the corresponding credentials to protected HTTP endpoints.

### Database Migrations

Apply the shipped PostgreSQL migrations before starting `gateway` or `orchestrator`:
Expand Down Expand Up @@ -83,15 +120,25 @@ Run the main integration suite:
go test ./internal/integration -count=1 -v
```

Run the distributed end-to-end flow separately with:

```bash
go test ./internal/integration -run TestDistributedStartExecuteTraceEndFlow -count=1 -v
```

## Public Interfaces

### MCP `stdio`

The `gateway --stdio` entry point exposes the full MCP tool catalog and is the simplest way to connect the project to AI tools and desktop clients.
The `gateway --stdio` entry point exposes the full MCP tool catalog and is the simplest way to connect the project to AI tools and desktop clients. It accepts modern per-request metadata and both supported legacy initialize revisions.

### MCP Streamable HTTP

The standard endpoint is `POST /mcp`. Modern `2026-07-28` requests are stateless and validate `MCP-Protocol-Version`, `Mcp-Method`, and method-specific `Mcp-Name` headers. Legacy `2025-11-25` and `2025-06-18` initialize flows remain supported.

### HTTP JSON-RPC

The `/jsonrpc` endpoint provides the same operational surface for service integrations that prefer HTTP transport.
The `/jsonrpc` endpoint preserves the operational surface for older service integrations, but it is not the standard MCP Streamable HTTP transport.

### WebSocket Event Streaming

Expand All @@ -114,9 +161,16 @@ using the issued token.
- `/healthz`
- `/metrics`

## Runtime Boundaries

- `monolith` is the supported gateway execution mode. Both HTTP and `stdio` embed the orchestrator in the gateway process.
- `distributed` remains experimental. The standalone orchestrator and worker implement capacity admission, leases, callbacks, recovery, and stale-result protection, but the gateway does not yet forward ingress traffic to an external orchestrator.
- Plan events are durable in PostgreSQL and published best-effort through Redis PubSub to the at-most-once WebSocket stream. Historical events are read through `getTrace`.
- `/metrics` currently shares the gateway listener; `telemetry.metrics_port` does not create a separate listener. Gateway and orchestrator initialize OTEL tracing, while worker currently uses structured logging.

## Tool Catalog

The repository exposes session, execution, element, gesture, screenshot, health, Device Farm, and optional debugging tools through MCP and JSON-RPC.
The repository contains 26 session, execution, element, gesture, screenshot, health, Device Farm, and debugging tools. The local example exposes all 26; the production example disables `adbShell` and therefore exposes 25.

Core interactive tools include:

Expand Down Expand Up @@ -193,6 +247,8 @@ Start from one of the shipped configuration templates:
- [config.example.yaml](./config.example.yaml) for local development
- [config.production.example.yaml](./config.production.example.yaml) for staging and production-style deployments

The production file is still a template. Replace all placeholder hosts, certificates, tokens, and database settings, and configure transport encryption and access controls for PostgreSQL, Redis, and S3 before deployment.

## Additional Documentation

- [Third-Party Integration Guide](./THIRD_PARTY_INTEGRATION.md)
Expand All @@ -201,6 +257,7 @@ Start from one of the shipped configuration templates:
- [Changelog](./CHANGELOG.md)
- [Release Notes v1.0.0](./RELEASE_NOTES_v1.0.0.md)
- [Security Policy](./SECURITY.md)
- [MCP 2026-07-28 Alignment](./MCP_2026_07_28_ALIGNMENT.md)
- [MIT License](./LICENSE)

## License
Expand Down
55 changes: 46 additions & 9 deletions THIRD_PARTY_INTEGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ This document describes the supported public integration paths for Tentacle.
| Interface | Typical Use Case | Transport |
| --- | --- | --- |
| MCP `stdio` | AI tools, desktop clients, local automation shells | stdio |
| HTTP JSON-RPC | backend services, API clients, CI systems | HTTP |
| MCP Streamable HTTP | standards-based remote MCP clients and gateways | HTTP `POST /mcp` |
| HTTP JSON-RPC compatibility | existing backend services, API clients, CI systems | HTTP `POST /jsonrpc` |
| WebSocket events | browser dashboards and live trace viewers | HTTP + WebSocket |

The repository also contains internal gRPC services for orchestrator-to-worker communication. Those services are runtime internals and are not part of the public third-party contract.
Expand Down Expand Up @@ -55,17 +56,53 @@ class MCPClient:
client = MCPClient("/absolute/path/to/gateway", "/absolute/path/to/config.yaml")

try:
print(client.call("initialize", {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {"name": "example-client", "version": "1.0.0"},
metadata = {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {},
"io.modelcontextprotocol/clientInfo": {
"name": "example-client",
"version": "1.0.0",
},
}
print(client.call("server/discover", {
"_meta": metadata,
}))
print(client.call("tools/list", {
"_meta": metadata,
}))
print(client.call("tools/list", {}))
finally:
client.close()
```

## 2. HTTP JSON-RPC
Legacy clients can still initialize with protocol version `2025-11-25` or `2025-06-18`.

## 2. MCP Streamable HTTP

Modern MCP `2026-07-28` requests are stateless and self-describing. Each request carries namespaced `_meta`, and the transport mirrors routing information through HTTP headers.

```bash
curl -X POST http://localhost:8080/mcp \
-H "Accept: application/json, text/event-stream" \
-H "Content-Type: application/json" \
-H "MCP-Protocol-Version: 2026-07-28" \
-H "Mcp-Method: tools/list" \
-d '{
"jsonrpc": "2.0",
"method": "tools/list",
"params": {
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientCapabilities": {},
"io.modelcontextprotocol/clientInfo": {"name": "remote-client", "version": "1.0.0"}
}
},
"id": 1
}'
```

`tools/call` and `resources/read` requests additionally send a matching `Mcp-Name` header. See [MCP 2026-07-28 Alignment](./MCP_2026_07_28_ALIGNMENT.md) for the complete compatibility and error matrix.

## 3. HTTP JSON-RPC Compatibility

Start the gateway:

Expand Down Expand Up @@ -134,7 +171,7 @@ curl -X POST http://localhost:8080/jsonrpc \
}'
```

## 3. Browser Event Streaming
## 4. Browser Event Streaming

Browser clients should mint a short-lived WebSocket token first:

Expand All @@ -158,7 +195,7 @@ ws.onmessage = (event) => {
};
```

## 4. AWS Device Farm
## 5. AWS Device Farm

### Scheduled Runs

Expand Down
Loading
Loading