MCP: server/discover (2026-07-28), resultType и кэш-подсказки; таблица передаёт выделение в контекст Claude (ui/update-model-context) и кнопка «Спросить Claude про выбранные» (ui/message)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -478,7 +478,29 @@ export function instructionsFromFile(text: string): string {
|
||||
const rpcError = (id: unknown, code: number, message: string): Json => ({ jsonrpc: "2.0", id: id ?? null, error: { code, message } });
|
||||
|
||||
/** Обрабатывает одно JSON-RPC сообщение от аутентифицированного человека; null - уведомление (ответа нет). */
|
||||
const SUPPORTED_VERSIONS = ["2026-07-28", "2025-11-25", "2025-06-18", "2025-03-26"];
|
||||
const SERVER_INFO = { name: "accounting_automation", version: "0.1.0" };
|
||||
const CAPABILITIES = { tools: { listChanged: true }, resources: {}, prompts: {}, extensions: { "io.modelcontextprotocol/ui": { mimeTypes: [REVIEW_UI_MIME] } } };
|
||||
|
||||
/** Подсказки кэширования (2026-07-28) для списков, discover и ресурсов; во всех результатах resultType: "complete". */
|
||||
const CACHE_HINTS: Record<string, { ttlMs: number; cacheScope: "public" | "private" }> = {
|
||||
"server/discover": { ttlMs: 60_000, cacheScope: "public" },
|
||||
"tools/list": { ttlMs: 60_000, cacheScope: "public" },
|
||||
"prompts/list": { ttlMs: 60_000, cacheScope: "public" },
|
||||
"resources/list": { ttlMs: 60_000, cacheScope: "public" },
|
||||
"resources/read": { ttlMs: 3_600_000, cacheScope: "public" }, // URI с хэшем содержимого
|
||||
};
|
||||
|
||||
export async function handleMcpMessage(tools: ReviewTools, personId: string, msg: Json, instructions: string = DEFAULT_INSTRUCTIONS): Promise<Json | null> {
|
||||
const res = await handleMcpInner(tools, personId, msg, instructions);
|
||||
if (res && res.result && typeof res.result === "object") {
|
||||
const hint = CACHE_HINTS[String(msg?.method)];
|
||||
res.result = { resultType: "complete", ...(res.result as Json), ...(hint ?? {}) };
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
async function handleMcpInner(tools: ReviewTools, personId: string, msg: Json, instructions: string): Promise<Json | null> {
|
||||
const id = msg?.id;
|
||||
const method = msg?.method;
|
||||
if (typeof method !== "string") return rpcError(id, -32600, "invalid request");
|
||||
@@ -486,7 +508,7 @@ export async function handleMcpMessage(tools: ReviewTools, personId: string, msg
|
||||
switch (method) {
|
||||
case "initialize": {
|
||||
const asked = (msg.params as Json | undefined)?.protocolVersion;
|
||||
return { jsonrpc: "2.0", id, result: { protocolVersion: typeof asked === "string" ? asked : "2025-03-26", capabilities: { tools: { listChanged: true }, resources: {}, prompts: {}, extensions: { "io.modelcontextprotocol/ui": { mimeTypes: [REVIEW_UI_MIME] } } }, serverInfo: { name: "accounting_automation", version: "0.1.0" }, instructions } };
|
||||
return { jsonrpc: "2.0", id, result: { protocolVersion: typeof asked === "string" ? asked : "2025-03-26", capabilities: CAPABILITIES, serverInfo: SERVER_INFO, instructions } };
|
||||
}
|
||||
case "ping":
|
||||
return { jsonrpc: "2.0", id, result: {} };
|
||||
@@ -511,6 +533,9 @@ export async function handleMcpMessage(tools: ReviewTools, personId: string, msg
|
||||
if (uri !== REVIEW_UI_URI && uri !== REVIEW_UI_URI_LEGACY) return rpcError(id, -32002, `ресурс не найден: ${String(uri)}`);
|
||||
return { jsonrpc: "2.0", id, result: { contents: [{ uri, mimeType: REVIEW_UI_MIME, text: REVIEW_UI_HTML, _meta: { ui: { prefersBorder: true, csp: { connectDomains: [], resourceDomains: [], frameDomains: [], baseUriDomains: [] } } } }] } };
|
||||
}
|
||||
case "server/discover":
|
||||
// версия 2026-07-28 (без initialize): Claude вызывает именно его
|
||||
return { jsonrpc: "2.0", id, result: { supportedVersions: SUPPORTED_VERSIONS, capabilities: CAPABILITIES, _meta: { "io.modelcontextprotocol/serverInfo": SERVER_INFO }, instructions } };
|
||||
case "tools/list":
|
||||
return { jsonrpc: "2.0", id, result: { tools: TOOLS } };
|
||||
case "tools/call": {
|
||||
|
||||
Reference in New Issue
Block a user