FilesLast commitLast update
8 hours ago
8 hours ago
11 hours ago
README

示例与交叉验证

本目录中的工程用于本地自测和每次发布前的交叉验证。每项验证只启动一个服务端主机,不覆盖不同主机配置(TLS、认证、监听地址等)。

examples/
├── stdio/
│   ├── cangjie/         # 仓颉 Client/Server stdio 自测
│   └── csharp/          # C# SDK stdio 互操作
└── http/
    ├── cangjie/         # 仓颉 Streamable HTTP 客户端与服务端
    └── csharp/          # C# Streamable HTTP Client/Server

前置条件

  • 仓颉工具链与 stdx,并设置 CANGJIE_STDX_PATH;运行仓颉可执行文件时让动态库搜索路径包含它。
  • .NET SDK 与本地 C# SDK 源码路径 McpSdkRoot。
  • C# 工程还原:
dotnet restore -p:McpSdkRoot=/path/to/csharp-sdk-main \
  --configfile /path/to/csharp-sdk-main/nuget.config

stdio 自测

cd examples/stdio/cangjie
cjpm build
./target/release/bin/main client ./target/release/bin/main

Windows 下二进制为 main.exe。

stdio C# 互操作

cd examples/stdio/cangjie
cjpm build
cd ../csharp
dotnet build --no-restore -p:McpSdkRoot=/path/to/csharp-sdk-main

# C# Client -> 仓颉 Server
dotnet bin/Debug/net10.0/csharp-interop.dll client ../cangjie/target/release/bin/main

# 仓颉 Client -> C# Server
cd ../cangjie
./target/release/bin/main client-interop ../csharp/bin/Debug/net10.0/csharp-interop

覆盖:server/discover、Tools、Resources、Prompts、Completion、分页、缓存、MRTR、进度、取消、订阅、过滤器与协议错误。

Streamable HTTP 互操作

cd examples/http/csharp
dotnet build --no-restore -p:McpSdkRoot=/path/to/csharp-sdk-main

# C# Server(Stateless Streamable HTTP)
dotnet bin/Debug/net10.0/csharp-http-interop.dll server 18082 &

# 仓颉 Client -> C# Server
cd ../cangjie
cjpm build
./target/release/bin/main client http://127.0.0.1:18082/mcp

# 仓颉 Server(run 直接启动,A 模式)
./target/release/bin/main server 127.0.0.1 18083 &

# C# Client -> 仓颉 Server
cd ../csharp
dotnet bin/Debug/net10.0/csharp-http-interop.dll client http://127.0.0.1:18083/mcp

# 仓颉 Server(自建 stdx 服务端,C 模式)
cd ../cangjie
./target/release/bin/main server-c 127.0.0.1 18084 &

覆盖:server/discover、tools/list、tools/call、SSE 进度、MRTR、未知工具与未知方法错误;A/C 两种仓颉服务端启动方式都与 C# 客户端完成双向验证。

OAuth 自测

examples/http/cangjie 内置最小 OAuth 授权服务器与受保护的 MCP 服务端:

cd examples/http/cangjie
cjpm build

# 受保护的 MCP + PRM + AS metadata + token endpoint
./target/release/bin/main auth-server 127.0.0.1 18085 &

# 客户端:PRM/AS 发现、PKCE S256、授权码交换、Bearer
./target/release/bin/main auth-client http://127.0.0.1:18085/mcp

覆盖:Protected Resource Metadata、Authorization Server Metadata、PKCE S256、resource 参数、Bearer 注入、token 缓存,以及无 token 时的 401 + WWW-Authenticate。