From 871bef3e4fc0cecb311e1f5d69005b4b34e76e15 Mon Sep 17 00:00:00 2001 From: yunyingk Date: Tue, 9 Jun 2026 11:55:56 +0800 Subject: [PATCH] Release seal-home 0.3.0 skill workflow --- README.md | 57 ++++++++- package.json | 2 +- skills/seal-home/SKILL.md | 175 +++++++++++++++++++++++++ skills/seal-home/agents/openai.yaml | 4 + skills/seal-home/references/cli.md | 190 ++++++++++++++++++++++++++++ src/domains/seal/tools.test.ts | 34 ++++- src/domains/seal/tools.ts | 141 +++++++++++++++++++++ src/server.ts | 18 +-- 8 files changed, 599 insertions(+), 22 deletions(-) create mode 100644 skills/seal-home/SKILL.md create mode 100644 skills/seal-home/agents/openai.yaml create mode 100644 skills/seal-home/references/cli.md diff --git a/README.md b/README.md index e27f13e..3fff6de 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # seal-home +Version: `0.3.0` + Bun + TypeScript MCP server for pulling Seal enterprise approval context from provider credentials. The first provider is Hose/合思: `key`, `password`, `corpId`, `staffId`, and an optional Hose domain. The provider exchanges those credentials for a Seal enterprise session, then the Seal domain tools can read and maintain approval rules, approval documents, and approval style preferences. @@ -18,9 +20,32 @@ bun run start For an already-authenticated Seal source, copy `enterprises/example.direct.json` instead. +## Public Usage + +This repository is intended to be published as a local agent toolkit. Users run the CLI and MCP server on their own machine with their own enterprise credentials; do not deploy the stdio MCP server as a shared public service without adding authentication, tenant isolation, credential storage, audit logging, and write-operation controls. + +```bash +git clone +cd seal-home +bun install +cp enterprises/example.hose.json enterprises/local.json +# Edit enterprises/local.json with your own Hose/Seal credentials. +bun run cli -- source config +bun run cli -- tools list +``` + +Local enterprise config files are ignored by git: + +```text +enterprises/*.json +!enterprises/example.*.json +``` + +The standard Codex skill lives at `skills/seal-home`. Install or copy that folder into a Codex skills directory when you want Codex to invoke the workflow as `$seal-home`. + ## CLI -The MCP server and CLI are separate entry points. Use MCP for protocol-native clients; use the CLI from skills, shell scripts, or agents that prefer command execution. +The MCP server and CLI are separate entry points. Use MCP for protocol-native clients; use the CLI from skills, shell scripts, or agents that prefer command execution. CLI intentionally keeps the full fine-grained tool list available through `seal-home tool `; only the MCP exported tool surface is narrowed for model context size. ```bash bun run cli -- tools list @@ -57,19 +82,38 @@ CLI output is JSON on stdout. Errors are written to stderr. } ``` -## Tools +## MCP Tools -- `seal_source_config`: resolve current Seal enterprise config from the configured source. +- `seal_corp_switch`: switch the active local enterprise config. - `seal_whoami`: current Seal user and tenant. -- `seal_session_get`: current Seal Bearer session and expiration. - `seal_approval_search`: keyword search across approval rules, documents, approval preferences, and optionally published rule history. Results include area, entity, field, line number, and surrounding context. Search data is cached in memory for 5 minutes. - `seal_approval_context_get`: read current approval rules, approval documents, and approval style preferences in one call. +- `seal_runs_search`: search the approval run history from `api/v1/approvals`. This is the broad record table for historical runs and returns compact run fields; set `includeBridge` only when full Langfuse bridge rows are needed. +- `seal_action`: low-frequency management router. Use `action: "help"` or `payload.topic` to discover actions. + +`seal_corps_list`, `seal_source_config`, and older fine-grained tool names are still accepted by the MCP call handler for compatibility, but they are not advertised by MCP `tools/list`. + +`seal_action` uses this shape: + +```json +{ + "action": "rule.create | rule.update | rule.publish | doc.create | doc.update | runs.summary | langfuse.bridge.get", + "payload": {} +} +``` + +## CLI/Internal Tools + +These tools remain available to the CLI and are also accepted by the MCP call handler for compatibility, but most are no longer advertised by MCP `tools/list`: + +- `seal_source_config`: resolve current Seal enterprise config from the configured source. +- `seal_approval_runs_search`: full internal name behind the MCP `seal_runs_search` alias. +- `seal_session_get`: current Seal Bearer session and expiration. - `seal_approval_rules_list`: current draft approval rules. - `seal_approval_rule_create`, `seal_approval_rule_update`, `seal_approval_rule_delete`: maintain approval rules. - `seal_approval_rule_versions_list`, `seal_approval_rule_version_publish`: read and publish rule versions. - `seal_approval_documents_list`, `seal_approval_document_get`, `seal_approval_document_create`, `seal_approval_document_update`: maintain approval documents. - `seal_approval_style_preferences_get`, `seal_approval_style_preferences_update`: read and update approval style preferences. -- `seal_approval_runs_search`: search the approval run history from `api/v1/approvals`. This is the broad record table for historical runs and returns compact run fields; set `includeBridge` only when full Langfuse bridge rows are needed. - `seal_approval_runs_summary`: summarize approval runs by local date and timezone. Use this for daily questions such as "what approval records did Tawen have today"; it returns status/task-mode counts and compact records. - `seal_simulation_batch_records_get`: read records from one simulation batch via `api/v1/simulation/batch/{batchId}/records`. - `seal_approval_run_langfuse_bridge_get`: resolve approval run records to Langfuse lookup hints. It prefers `sourceExtendData._langfuseTraceId`; if that is missing, it returns `hosecloud-{sourceDocumentSN}` as the session fallback. @@ -98,6 +142,7 @@ When `_langfuseTraceId` exists, downstream tools should fetch the trace directly - Prefer Bun-native commands in this repository: `bun run check`, `bun test`, and `bun run cli -- ...`. `npm run check` may work, but Bun is the project runtime and lockfile owner. - Keep MCP and CLI as thin entry points. Shared behavior belongs in `src/core` and `src/domains`; `src/server.ts` should only handle MCP protocol concerns, and `src/cli.ts` should only handle command parsing and JSON output. - Do not print diagnostic text to stdout from the MCP server. MCP uses stdout as the protocol stream; use stderr for server diagnostics. -- Prefer CLI or script processing for large tool responses. For daily approval questions, call `seal_approval_runs_summary` or `bun run cli -- approval-runs summary ...` instead of reading long `seal_approval_runs_search` output manually. +- Keep the MCP exported surface narrow. High-frequency read tools can be direct MCP tools; low-frequency maintenance should go through `seal_action` or CLI commands. +- Prefer CLI or script processing for large tool responses. For daily approval questions, call `seal_action` with `runs.summary` or `bun run cli -- approval-runs summary ...` instead of reading long `seal_approval_runs_search` output manually. - Keep broad search tools compact by default. Add explicit opt-in flags such as `includeBridge` for verbose fields that are useful only in deeper debugging. - When Seal API timestamp filters are uncertain, filter again in tool code by `createdAt` and explicit timezone before presenting date-based answers. diff --git a/package.json b/package.json index 8538394..5b91039 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "seal-home", - "version": "0.1.0", + "version": "0.3.0", "type": "module", "module": "src/server.ts", "bin": { diff --git a/skills/seal-home/SKILL.md b/skills/seal-home/SKILL.md new file mode 100644 index 0000000..ec8b82e --- /dev/null +++ b/skills/seal-home/SKILL.md @@ -0,0 +1,175 @@ +--- +name: seal-home +description: Use when working with Seal Home / seal-home approval automation: querying Seal enterprise identity, approval rules, approval knowledge documents, approval style preferences, approval run history, simulation batch records, and Langfuse trace/session bridge hints. Prefer this skill when the user mentions Seal, seal_home MCP, 合思/易快报 approval runs, approval rule/document maintenance, approval simulations, or debugging Seal approval execution traces. +--- + +# Seal Home + +## Quick Start + +Run commands from the seal-home repository root: + +```bash +bun run cli -- help +bun run cli -- tools list +``` + +Use CLI for broad or detailed operations. Use MCP for narrow, high-frequency agent entry points only. The CLI intentionally exposes the full fine-grained tool list; MCP intentionally advertises a small surface to reduce model context. + +## Decision Guide + +- For current identity or tenant: use `bun run cli -- tool seal_whoami`. +- For configured enterprises: use `bun run cli -- corps list`. +- For source-derived enterprise config: use `bun run cli -- source config`. +- For daily approval run questions: use `bun run cli -- approval-runs summary --date YYYY-MM-DD --timezone Asia/Shanghai`. +- For approval run lookup by document SN, ID, status, mode, or trace: use `bun run cli -- approval-runs search`. +- For Langfuse lookup hints: use `bun run cli -- approval-runs bridge`. +- For one simulation batch: use `bun run cli -- simulation batch-records `. +- For approval rule/document/style maintenance: use `bun run cli -- tool --json '{...}'`. + +## Task Playbooks + +### Diagnose one approval document + +Use when the user gives a 合思/易快报单号, Seal source document SN, source document ID, or asks why one approval did or did not pass. + +1. Search runs: + +```bash +bun run cli -- approval-runs search --query --limit 50 +``` + +2. If a likely record is found, get bridge hints: + +```bash +bun run cli -- approval-runs bridge --sourceDocumentSN +``` + +3. Report `status`, `taskMode`, `finalExecutionMode`, `recordId`, `simulationBatchId`, `langfuseTraceId`, and `langfuseSessionFallback`. If `langfuseTraceId` is absent, tell the caller to use the session fallback. + +### Summarize one day of approval runs + +Use explicit local date and timezone: + +```bash +bun run cli -- approval-runs summary --date YYYY-MM-DD --timezone Asia/Shanghai --limit 100 +``` + +Report matched count, status counts, task mode counts, and the most relevant failed or simulated records. If `matched` is unexpectedly low, rerun with broader `limit` or targeted `query`. + +### Inspect a simulation batch + +```bash +bun run cli -- simulation batch-records +``` + +Summarize count, statuses, source document identifiers, and bridge hints. For failures, preserve record IDs so another tool can inspect the trace. + +### Search approval knowledge + +Use for "which rule/document mentions X" or before changing rule/document content: + +```bash +bun run cli -- tool seal_approval_search --json '{"keywords":["关键词"],"matchMode":"any","maxResults":20}' +``` + +Use `areas` to narrow to `rules`, `documents`, or `preferences`. Use `refresh:true` when recent edits may not be reflected in the in-memory cache. + +### Update approval rules + +Write workflow: + +1. Read current rules with `seal_approval_rules_list` or `seal_approval_context_get`. +2. Identify the exact rule ID or create payload. +3. Present the intended change and ask for confirmation. +4. Run `seal_approval_rule_create`, `seal_approval_rule_update`, or `seal_approval_rule_delete`. +5. Read rules again to verify. +6. Publish only when explicitly requested, using `seal_approval_rule_version_publish` with a clear `versionName`. + +### Update approval documents + +Write workflow: + +1. List or fetch the target document. +2. Present the intended title/purpose/content/status/scenario/tag change. +3. Ask for confirmation. +4. Run `seal_approval_document_create` or `seal_approval_document_update`. +5. Fetch the document again to verify. + +There is no dedicated delete command in the current CLI. If deactivation is intended and the API supports it, update with `enabled:false`. + +### Update style preferences + +Read first: + +```bash +bun run cli -- tool seal_approval_style_preferences_get +``` + +Then update only explicit fields: + +```bash +bun run cli -- tool seal_approval_style_preferences_update --json '{"tone":"...","language":"..."}' +``` + +Verify by reading again. + +## Important Fields + +- `sourceDocumentSN`: external source document number, often the easiest 合思/易快报 lookup key. +- `sourceDocumentId`: external source document ID. +- `status`: run status such as completed or failed. +- `taskMode`: execution mode category such as assisted or simulation. +- `finalExecutionMode`: final mode chosen by the approval agent. +- `recordId`: Seal approval run record ID. +- `simulationBatchId`: simulation batch identifier when the run came from a batch. +- `langfuseTraceId`: direct Langfuse trace lookup key when present. +- `langfuseSessionFallback`: fallback session key, usually `hosecloud-{sourceDocumentSN}`, when direct trace ID is absent. + +## MCP Boundary + +The MCP server advertises only these tools: + +- `seal_corp_switch` +- `seal_whoami` +- `seal_approval_search` +- `seal_approval_context_get` +- `seal_runs_search` +- `seal_action` + +Do not add every backend API operation as an MCP tool. Add stable, frequent read operations directly; route low-frequency management through `seal_action` or CLI. + +`seal_action` examples: + +```json +{ "action": "help", "payload": { "topic": "rule" } } +{ "action": "rule.create", "payload": { "description": "...", "scope": "...", "strictness": "SHOULD_FOLLOW" } } +{ "action": "doc.update", "payload": { "documentId": "...", "content": "..." } } +{ "action": "runs.summary", "payload": { "date": "2026-06-09", "timezone": "Asia/Shanghai" } } +{ "action": "langfuse.bridge.get", "payload": { "sourceDocumentSN": "B26001887" } } +``` + +## CLI Patterns + +Read `references/cli.md` when you need the full tool list, parameter examples, or maintenance commands. + +Preferred command forms: + +```bash +bun run cli -- approval-runs summary --date 2026-06-09 --timezone Asia/Shanghai +bun run cli -- approval-runs search --query B26001887 --limit 20 --includeBridge true +bun run cli -- approval-runs bridge --sourceDocumentSN B26001887 +bun run cli -- tool seal_approval_search --json '{"keywords":["差旅","发票"],"areas":["rules","documents"]}' +``` + +## Output Handling + +CLI output is JSON on stdout. Parse JSON instead of scraping text. Keep broad responses compact: avoid `includeBridge true` unless trace/session bridge rows are needed. + +For date-based questions, use explicit dates and timezone. Default timezone is usually `Asia/Shanghai`; pass it explicitly when answering business questions. + +## Safety + +Rule, document, style preference, and publish actions mutate Seal configuration. Before running write operations, make sure the target enterprise is clear and the requested payload is explicit. Prefer listing or fetching the current state before update/delete/publish. + +For public or shared use, assume the CLI runs locally with the user's own credentials. Do not send real `enterprises/*.json` files to GitHub, chat, logs, or tickets. diff --git a/skills/seal-home/agents/openai.yaml b/skills/seal-home/agents/openai.yaml new file mode 100644 index 0000000..6dbbdcb --- /dev/null +++ b/skills/seal-home/agents/openai.yaml @@ -0,0 +1,4 @@ +interface: + display_name: "Seal Home" + short_description: "Use Seal approval context and run diagnostics" + default_prompt: "Use $seal-home to inspect Seal approval rules, documents, run history, and Langfuse trace hints." diff --git a/skills/seal-home/references/cli.md b/skills/seal-home/references/cli.md new file mode 100644 index 0000000..d6bc972 --- /dev/null +++ b/skills/seal-home/references/cli.md @@ -0,0 +1,190 @@ +# Seal Home CLI Reference + +Run from the repository root: + +```bash +bun run cli -- +``` + +## Top-Level Commands + +```bash +bun run cli -- tools list +bun run cli -- corps list [--corp ] +bun run cli -- source config [--corp ] +bun run cli -- tool [--corp ] [--json '{"key":"value"}'] +bun run cli -- approval-runs summary [--date YYYY-MM-DD] [--timezone Asia/Shanghai] +bun run cli -- approval-runs search [--query text] [--limit 20] [--includeBridge true] +bun run cli -- approval-runs bridge [--sourceDocumentSN B26001887] +bun run cli -- simulation batch-records +``` + +## Fine-Grained Tools + +Identity and session: + +- `seal_whoami` +- `seal_session_get` + +Approval rule maintenance: + +- `seal_approval_rules_list` +- `seal_approval_rule_create` +- `seal_approval_rule_update` +- `seal_approval_rule_delete` +- `seal_approval_rule_versions_list` +- `seal_approval_rule_version_publish` + +Approval knowledge documents: + +- `seal_approval_documents_list` +- `seal_approval_document_get` +- `seal_approval_document_create` +- `seal_approval_document_update` + +Approval search and context: + +- `seal_approval_search` +- `seal_approval_context_get` + +Style preferences: + +- `seal_approval_style_preferences_get` +- `seal_approval_style_preferences_update` + +Approval runs, simulations, and Langfuse bridge: + +- `seal_approval_runs_search` +- `seal_approval_runs_summary` +- `seal_simulation_batch_records_get` +- `seal_approval_run_langfuse_bridge_get` + +## Common Examples + +Search approval content: + +```bash +bun run cli -- tool seal_approval_search --json '{"keywords":["关键词"],"matchMode":"any","maxResults":20}' +``` + +Get aggregated approval context: + +```bash +bun run cli -- tool seal_approval_context_get --json '{"documentLimit":20}' +``` + +Create a draft approval rule: + +```bash +bun run cli -- tool seal_approval_rule_create --json '{"description":"规则描述","scope":"适用场景","strictness":"SHOULD_FOLLOW"}' +``` + +Update an approval document: + +```bash +bun run cli -- tool seal_approval_document_update --json '{"documentId":"doc-id","content":"Markdown 内容"}' +``` + +Summarize one local date: + +```bash +bun run cli -- approval-runs summary --date 2026-06-09 --timezone Asia/Shanghai --limit 100 +``` + +Find a run and include Langfuse bridge rows: + +```bash +bun run cli -- approval-runs search --query B26001887 --limit 20 --includeBridge true +``` + +Resolve Langfuse trace/session hints: + +```bash +bun run cli -- approval-runs bridge --sourceDocumentSN B26001887 +``` + +Read simulation batch records: + +```bash +bun run cli -- simulation batch-records +``` + +## Write Operation Payloads + +Create a rule: + +```json +{ + "description": "规则描述", + "scope": "适用场景", + "strictness": "MUST_FOLLOW | SHOULD_FOLLOW | SUGGESTION" +} +``` + +Update a rule: + +```json +{ + "ruleId": "rule-id", + "description": "可选", + "scope": "可选", + "strictness": "SHOULD_FOLLOW" +} +``` + +Publish a rule version: + +```json +{ + "versionName": "版本名称" +} +``` + +Create a document: + +```json +{ + "title": "标题", + "purpose": "用途", + "content": "Markdown 内容", + "contentType": "text/markdown", + "status": "可选", + "scenarios": ["场景"], + "tags": ["标签"] +} +``` + +Update a document: + +```json +{ + "documentId": "doc-id", + "title": "可选", + "purpose": "可选", + "content": "可选", + "enabled": true, + "scenarios": ["可选"], + "tags": ["可选"] +} +``` + +Update style preferences: + +```json +{ + "tone": "可选", + "language": "可选", + "detailLevel": "可选", + "outputFormat": "可选", + "examples": ["可选"], + "prohibitedPhrases": ["可选"], + "customInstructions": "可选" +} +``` + +## Failure Handling + +- If no run is found by `sourceDocumentSN`, retry with `sourceDocumentId` or a broader `query`. +- If date-based summaries look wrong, pass `--timezone Asia/Shanghai` and an explicit `--date`. +- If `langfuseTraceId` is missing, use `langfuseSessionFallback`. +- If a write operation fails, report the raw JSON error and do not retry with guessed payloads. diff --git a/src/domains/seal/tools.test.ts b/src/domains/seal/tools.test.ts index 3323375..5c02377 100644 --- a/src/domains/seal/tools.test.ts +++ b/src/domains/seal/tools.test.ts @@ -1,7 +1,7 @@ import { describe, expect, test } from "bun:test"; import { KyInstance } from "ky"; import { z } from "zod"; -import { sealTools } from "./tools.js"; +import { findSealMcpTool, findSealTool, sealMcpTools, sealTools } from "./tools.js"; type ToolHandler = ( client: KyInstance, @@ -49,6 +49,38 @@ describe("sealTools", () => { expect(sealTools.find((item) => item.name === "seal_approval_run_langfuse_bridge_get")).toBeDefined(); }); + test("keeps the MCP exposed tool surface narrow", () => { + expect(sealMcpTools.map((tool) => tool.name)).toEqual([ + "seal_whoami", + "seal_approval_search", + "seal_approval_context_get", + "seal_runs_search", + "seal_action" + ]); + }); + + test("routes low-frequency management tools through seal_action", async () => { + const tool = sealMcpTools.find((item) => item.name === "seal_action"); + expect(tool).toBeDefined(); + + const handler = tool!.handler as ToolHandler; + const result = await handler( + fakeApprovalRunsClient(), + { action: "runs.summary", payload: { date: "2026-06-08", timezone: "Asia/Shanghai" } }, + fakeContext() + ) as { matched: number }; + + expect(result.matched).toBe(2); + }); + + test("keeps old fine-grained tools available to compatibility callers but hidden from MCP list", () => { + expect(sealMcpTools.find((item) => item.name === "seal_approval_rule_create")).toBeUndefined(); + expect(findSealMcpTool("seal_approval_rule_create")).toBeUndefined(); + expect(findSealTool("seal_approval_rule_create")).toBeDefined(); + expect(findSealMcpTool("seal_action")).toBeDefined(); + expect(findSealMcpTool("seal_runs_search")?.name).toBe("seal_runs_search"); + }); + test("approval run search omits bridge unless requested", async () => { const tool = sealTools.find((item) => item.name === "seal_approval_runs_search"); expect(tool).toBeDefined(); diff --git a/src/domains/seal/tools.ts b/src/domains/seal/tools.ts index 0d894ab..179c984 100644 --- a/src/domains/seal/tools.ts +++ b/src/domains/seal/tools.ts @@ -9,6 +9,13 @@ type ToolContext = { corp: CorpConfig; }; +type SealToolDefinition = { + name: string; + description: string; + parameters: z.ZodType; + handler: (client: KyInstance, params: never, context: ToolContext) => Promise; +}; + export const sealTools = [ { name: "seal_whoami", @@ -405,6 +412,140 @@ export const sealTools = [ export type SealTool = (typeof sealTools)[number]; +const sealToolByName = new Map( + sealTools.map((tool) => [tool.name, tool]) +); + +const mcpDirectToolNames = [ + "seal_whoami", + "seal_approval_search", + "seal_approval_context_get" +] as const; + +const sealActionNames = [ + "seal_session_get", + "seal_approval_rules_list", + "seal_approval_rule_create", + "seal_approval_rule_update", + "seal_approval_rule_delete", + "seal_approval_rule_versions_list", + "seal_approval_rule_version_publish", + "seal_approval_documents_list", + "seal_approval_document_get", + "seal_approval_document_create", + "seal_approval_document_update", + "seal_approval_style_preferences_get", + "seal_approval_style_preferences_update", + "seal_approval_runs_summary", + "seal_simulation_batch_records_get", + "seal_approval_run_langfuse_bridge_get" +] as const; + +const sealActionAliases: Record = { + "session.get": "seal_session_get", + "rule.list": "seal_approval_rules_list", + "rule.create": "seal_approval_rule_create", + "rule.update": "seal_approval_rule_update", + "rule.delete": "seal_approval_rule_delete", + "rule.versions.list": "seal_approval_rule_versions_list", + "rule.publish": "seal_approval_rule_version_publish", + "doc.list": "seal_approval_documents_list", + "doc.get": "seal_approval_document_get", + "doc.create": "seal_approval_document_create", + "doc.update": "seal_approval_document_update", + "style.get": "seal_approval_style_preferences_get", + "style.update": "seal_approval_style_preferences_update", + "runs.summary": "seal_approval_runs_summary", + "batch.records.get": "seal_simulation_batch_records_get", + "langfuse.bridge.get": "seal_approval_run_langfuse_bridge_get" +}; + +export const sealMcpTools: SealToolDefinition[] = [ + ...mcpDirectToolNames.map((name) => requiredTool(name)), + { + ...requiredTool("seal_approval_runs_search"), + name: "seal_runs_search", + description: "查询 Seal 审批/审核运行记录,返回精简记录并按需提供 Langfuse trace/session 关联" + }, + { + name: "seal_action", + description: "Seal 低频管理操作统一入口。传 action=help 查看可用动作;支持 rule/doc/style/runs/batch/langfuse 等管理与诊断操作。", + parameters: z.object({ + action: z.string().describe("动作名,如 help、rule.create、doc.update、runs.summary、langfuse.bridge.get;也兼容旧 tool 名"), + payload: z.record(z.string(), z.unknown()).optional().describe("动作参数对象") + }), + handler: async ( + client: KyInstance, + params: { action: string; payload?: Record }, + context: ToolContext + ) => runSealAction(client, params, context) + } +]; + +export function findSealTool(name: string, options: { includeMcpAliases?: boolean } = {}) { + if (options.includeMcpAliases && name === "seal_runs_search") { + return requiredTool("seal_approval_runs_search"); + } + return sealToolByName.get(name); +} + +export function findSealMcpTool(name: string) { + return sealMcpTools.find((tool) => tool.name === name); +} + +async function runSealAction( + client: KyInstance, + params: { action: string; payload?: Record }, + context: ToolContext +) { + const action = params.action?.trim(); + if (!action || action === "help") { + return sealActionHelp(params.payload?.topic); + } + + const toolName = sealActionAliases[action] ?? action; + if (!isSealActionToolName(toolName)) { + return { + error: `Unsupported seal_action action: ${action}`, + help: sealActionHelp(params.payload?.topic) + }; + } + + const tool = requiredTool(toolName); + const payload = params.payload ?? {}; + return tool.handler(client, payload as never, context); +} + +function sealActionHelp(topic: unknown) { + const normalizedTopic = typeof topic === "string" ? topic.trim() : undefined; + const actions = Object.entries(sealActionAliases) + .filter(([action]) => !normalizedTopic || action.startsWith(`${normalizedTopic}.`)) + .map(([action, toolName]) => { + const tool = requiredTool(toolName); + return { + action, + toolName, + description: tool.description + }; + }); + + return { + usage: "seal_action({ action, payload })", + topics: ["session", "rule", "doc", "style", "runs", "batch", "langfuse"], + actions + }; +} + +function requiredTool(name: string): SealTool { + const tool = sealToolByName.get(name); + if (!tool) throw new Error(`Missing Seal tool: ${name}`); + return tool; +} + +function isSealActionToolName(name: string): name is (typeof sealActionNames)[number] { + return sealActionNames.includes(name as (typeof sealActionNames)[number]); +} + type ApprovalRunSummary = { id: string; tenantId?: string; diff --git a/src/server.ts b/src/server.ts index 91c8411..8ffe81e 100644 --- a/src/server.ts +++ b/src/server.ts @@ -9,7 +9,7 @@ import { loadCorpConfigs } from "./core/config/loader.js"; import { CorpContext } from "./core/config/manager.js"; import { createSealClient } from "./core/http/factory.js"; import { resolveLiveSealEnterpriseConfig } from "./domains/seal/source.js"; -import { sealTools } from "./domains/seal/tools.js"; +import { findSealMcpTool, findSealTool, sealMcpTools } from "./domains/seal/tools.js"; async function main() { const corps = loadCorpConfigs(); @@ -18,7 +18,7 @@ async function main() { const server = new Server( { name: "seal-home", - version: "0.1.0" + version: "0.3.0" }, { capabilities: { @@ -29,11 +29,6 @@ async function main() { server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ - { - name: "seal_corps_list", - description: "列出本地配置的 Seal 企业", - inputSchema: { type: "object", properties: {} } - }, { name: "seal_corp_switch", description: "切换当前 Seal 企业", @@ -45,12 +40,7 @@ async function main() { required: ["corpId"] } }, - { - name: "seal_source_config", - description: "通过当前来源认证并读取 Seal 租户信息,解析 Seal 企业配置", - inputSchema: { type: "object", properties: {} } - }, - ...sealTools.map((tool) => ({ + ...sealMcpTools.map((tool) => ({ name: tool.name, description: tool.description, inputSchema: z.toJSONSchema(tool.parameters) @@ -91,7 +81,7 @@ async function main() { return textResult(await resolveLiveSealEnterpriseConfig(currentCorp)); } - const tool = sealTools.find((item) => item.name === name); + const tool = findSealMcpTool(name) ?? findSealTool(name); if (!tool) { return textResult({ error: `Unknown tool: ${name}` }, true); }