Skip to main content

Keystone 平台 MCP Service SDK(Python)

Project description

ks-app-sdk (Python)

Keystone 平台 MCP Service SDK(Python 版)。

安装

pip install ks-app-sdk>=0.3.0

快速上手

from ks_app import App

app = App(
    "my-app",
    keystone_auth=True,           # 启用 JWKS strict-by-default
    version="0.1.0",
    manifest_path="manifest.yaml",
)


@app.tool("greet", "打招呼")
async def greet(name: str = "world"):
    return {"message": f"Hello, {name}!"}


# 可选:挂 /config-ui/ 静态前端
# app.mount_config_ui("./web/dist")

# 可选:扩展健康检查
# app.health_check("db", check_db_connection)

if __name__ == "__main__":
    app.run()

鉴权

启用 keystone_auth=True 后,对 /mcp 前缀的请求会强制 JWKS RS256 JWT 验签。

环境变量:

变量 说明
KEYSTONE_JWKS_URL 生产必须设置,指向 Keystone 的 .well-known/jwks.json
KS_APP_AUTH_MODE=insecure 本地开发降级为裸跑(跳过所有鉴权)
KS_APP_PORT / KS_APP_HOST 进程监听配置

strict-by-default:若 keystone_auth=TrueKEYSTONE_JWKS_URL 未配置, app.create_app() 会抛 AuthResolveError。生产意外漏配时立即暴露,不会静默裸跑。

在工具 handler 中读取 JWT claims:

from ks_app import get_claims


@app.tool("whoami", "查当前用户")
async def whoami():
    claims = get_claims()
    return {"sub": claims.get("sub") if claims else None}

端点

路径 方法 说明
/healthz GET 存活探针(聚合自定义 health_check
/readyz GET 就绪探针
/meta GET 应用元信息(对齐 ks-types.MetaResponse
/mcp POST MCP Streamable HTTP,JSON-RPC 2.0
/mcp/tools/list GET 工具列表(legacy)
/mcp/tools/call POST 调用工具(legacy)
/config-ui/* GET 前端静态资源(调用 mount_config_ui 后挂载)

配置

环境变量 默认值 说明
KS_APP_PORT 8080 监听端口
KS_APP_HOST 0.0.0.0 监听地址
KEYSTONE_JWKS_URL JWKS 端点;keystone_auth=True 必配
KS_APP_AUTH_MODE insecure 时强制跳过鉴权

依赖

  • uvicorn>=0.30
  • starlette>=0.37
  • pyyaml>=6.0
  • PyJWT[crypto]>=2.8.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ks_app_sdk-0.3.1.tar.gz (33.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ks_app_sdk-0.3.1-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file ks_app_sdk-0.3.1.tar.gz.

File metadata

  • Download URL: ks_app_sdk-0.3.1.tar.gz
  • Upload date:
  • Size: 33.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for ks_app_sdk-0.3.1.tar.gz
Algorithm Hash digest
SHA256 3f65f4e67192c2dc16c2623b80da9cfd1f5dcebde666c7573a32c5a718f51c16
MD5 cc10bccef09d230c5bef9d3fa9f33b68
BLAKE2b-256 1fca9941bc14557d9b8a78be58aada24f4f572661c4e8ad9adc9ca4ca4b16a28

See more details on using hashes here.

File details

Details for the file ks_app_sdk-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: ks_app_sdk-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for ks_app_sdk-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2a2b413a0b9ab29ae87f5c7deb9f583904e5fad9c63542d3d5159aae71eab3cd
MD5 a08404eab4d071cde9d01b2fb7b2705e
BLAKE2b-256 4f50b9b905b58add0c7ceb4db93ce2d4b7aae868da347261480451340c383181

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page