@frihet/mcp-server 1.16.6 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +168 -82
- package/dist/agent-onboarding.d.ts +98 -0
- package/dist/agent-onboarding.js +275 -0
- package/dist/api-origin.d.ts +9 -0
- package/dist/api-origin.js +41 -0
- package/dist/canary/mcp-harness.d.ts +77 -0
- package/dist/canary/mcp-harness.js +552 -0
- package/dist/capability-truth.d.ts +29 -0
- package/dist/capability-truth.js +262 -0
- package/dist/claude-candidate-contract.d.ts +482 -0
- package/dist/claude-candidate-contract.js +87 -0
- package/dist/claude-output-privacy.d.ts +17 -0
- package/dist/claude-output-privacy.js +240 -0
- package/dist/claude-profile.d.ts +18 -0
- package/dist/claude-profile.js +260 -0
- package/dist/client-interface.d.ts +47 -33
- package/dist/client.d.ts +172 -40
- package/dist/client.js +708 -165
- package/dist/demo-client.d.ts +41 -32
- package/dist/demo-client.js +202 -31
- package/dist/demo-fixtures.d.ts +3 -3
- package/dist/demo-fixtures.js +7 -7
- package/dist/deposit-contract.d.ts +29 -0
- package/dist/deposit-contract.js +76 -0
- package/dist/fetch-no-redirect.d.ts +3 -0
- package/dist/fetch-no-redirect.js +16 -0
- package/dist/fiscal-aliases.d.ts +44 -0
- package/dist/fiscal-aliases.js +62 -0
- package/dist/fiscal-period.d.ts +26 -0
- package/dist/fiscal-period.js +31 -0
- package/dist/google-profile.d.ts +19 -0
- package/dist/google-profile.js +122 -0
- package/dist/index.js +68 -59
- package/dist/logger.d.ts +2 -2
- package/dist/logger.js +140 -8
- package/dist/muse-profile.d.ts +19 -0
- package/dist/muse-profile.js +122 -0
- package/dist/observability.d.ts +18 -29
- package/dist/observability.js +194 -106
- package/dist/openai-profile.d.ts +26 -22
- package/dist/openai-profile.js +1193 -157
- package/dist/openai-review-contract.d.ts +15 -6
- package/dist/openai-review-contract.js +714 -41
- package/dist/openai-review-oauth.d.ts +149 -2
- package/dist/openai-review-oauth.js +220 -6
- package/dist/prompts/register-all.d.ts +2 -0
- package/dist/prompts/register-all.js +34 -78
- package/dist/public-capability-contract.d.ts +39 -0
- package/dist/public-capability-contract.js +186 -0
- package/dist/redaction.d.ts +15 -0
- package/dist/redaction.js +83 -0
- package/dist/resources/register-all.js +154 -64
- package/dist/retry-after.d.ts +19 -0
- package/dist/retry-after.js +84 -0
- package/dist/server-composition.d.ts +19 -0
- package/dist/server-composition.js +74 -0
- package/dist/tool-exposure.d.ts +31 -27
- package/dist/tool-exposure.js +211 -87
- package/dist/tools/accountingClose.d.ts +14 -5
- package/dist/tools/accountingClose.js +41 -23
- package/dist/tools/audit_gl.js +8 -8
- package/dist/tools/backend-availability.d.ts +8 -29
- package/dist/tools/backend-availability.js +31 -30
- package/dist/tools/bank_rules.js +66 -15
- package/dist/tools/banking.js +5 -13
- package/dist/tools/clients.js +261 -15
- package/dist/tools/crm.js +22 -21
- package/dist/tools/deposits.js +114 -85
- package/dist/tools/einvoice.d.ts +16 -2
- package/dist/tools/einvoice.js +59 -12
- package/dist/tools/expenses.d.ts +16 -0
- package/dist/tools/expenses.js +47 -27
- package/dist/tools/fiscal.d.ts +3 -4
- package/dist/tools/fiscal.js +93 -60
- package/dist/tools/gestoria.js +15 -7
- package/dist/tools/hr.d.ts +2 -3
- package/dist/tools/hr.js +49 -20
- package/dist/tools/igic.d.ts +9 -8
- package/dist/tools/igic.js +34 -64
- package/dist/tools/impuesto_sociedades.d.ts +4 -5
- package/dist/tools/impuesto_sociedades.js +16 -37
- package/dist/tools/intelligence.js +166 -12
- package/dist/tools/invoices.js +224 -54
- package/dist/tools/kitchen.js +19 -9
- package/dist/tools/payroll.d.ts +5 -8
- package/dist/tools/payroll.js +19 -32
- package/dist/tools/permissions.d.ts +4 -7
- package/dist/tools/permissions.js +11 -14
- package/dist/tools/products.js +6 -6
- package/dist/tools/quotes.js +172 -26
- package/dist/tools/recurring.js +26 -25
- package/dist/tools/register-all.d.ts +2 -2
- package/dist/tools/register-all.js +9 -6
- package/dist/tools/search.d.ts +19 -0
- package/dist/tools/search.js +84 -0
- package/dist/tools/shared.d.ts +1445 -109
- package/dist/tools/shared.js +478 -102
- package/dist/tools/team.js +24 -28
- package/dist/tools/time.js +4 -12
- package/dist/tools/vendors.js +249 -15
- package/dist/tools/webhooks.js +35 -30
- package/dist/types.d.ts +31 -5
- package/dist/workflows/daily-operational-brief.d.ts +163 -0
- package/dist/workflows/daily-operational-brief.js +881 -0
- package/docs/agent-onboarding.json +391 -0
- package/package.json +49 -12
- package/dist/tools/onboarding.d.ts +0 -19
- package/dist/tools/onboarding.js +0 -64
package/dist/logger.js
CHANGED
|
@@ -6,6 +6,107 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Set FRIHET_MCP_DEBUG=1 to enable debug-level logs.
|
|
8
8
|
*/
|
|
9
|
+
const OPERATION_MESSAGES = {
|
|
10
|
+
startup: "MCP startup event",
|
|
11
|
+
session_init: "MCP session event",
|
|
12
|
+
tool_call: "MCP tool call completed",
|
|
13
|
+
tool_error: "MCP tool error",
|
|
14
|
+
api_call: "MCP API call completed",
|
|
15
|
+
api_retry: "MCP API retry scheduled",
|
|
16
|
+
http_request: "MCP HTTP request completed",
|
|
17
|
+
oauth_authorize: "MCP OAuth authorization event",
|
|
18
|
+
oauth_callback: "MCP OAuth callback event",
|
|
19
|
+
shutdown_metrics: "MCP shutdown event",
|
|
20
|
+
langfuse_send: "MCP telemetry delivery event",
|
|
21
|
+
langfuse_trace: "MCP telemetry trace event",
|
|
22
|
+
};
|
|
23
|
+
const TOOL_NAME = /^[a-z][a-z0-9_]{0,63}$/u;
|
|
24
|
+
const PACKAGE_VERSION = /^\d{1,3}\.\d{1,3}\.\d{1,3}$/u;
|
|
25
|
+
const SAFE_METHODS = new Set(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"]);
|
|
26
|
+
const SAFE_TRANSPORTS = new Set(["stdio", "remote"]);
|
|
27
|
+
const SAFE_MCP_VERSIONS = new Set(["mcp/1.0"]);
|
|
28
|
+
const LOCAL_ERROR_CODES = new Set([
|
|
29
|
+
"tool_error",
|
|
30
|
+
"telemetry_http_error",
|
|
31
|
+
"telemetry_error",
|
|
32
|
+
"startup_error",
|
|
33
|
+
"unknown_error",
|
|
34
|
+
]);
|
|
35
|
+
function toolNameToken(value) {
|
|
36
|
+
return typeof value === "string" && TOOL_NAME.test(value) ? value : undefined;
|
|
37
|
+
}
|
|
38
|
+
function operationalErrorCode(value, statusCode) {
|
|
39
|
+
if (statusCode === 401)
|
|
40
|
+
return "unauthorized";
|
|
41
|
+
if (statusCode === 403)
|
|
42
|
+
return "forbidden";
|
|
43
|
+
if (statusCode === 404)
|
|
44
|
+
return "not_found";
|
|
45
|
+
if (statusCode === 408)
|
|
46
|
+
return "request_timeout";
|
|
47
|
+
if (statusCode === 429)
|
|
48
|
+
return "rate_limited";
|
|
49
|
+
if (statusCode !== undefined && statusCode >= 400 && statusCode < 500)
|
|
50
|
+
return "client_error";
|
|
51
|
+
if (statusCode !== undefined && statusCode >= 500)
|
|
52
|
+
return "backend_error";
|
|
53
|
+
return typeof value === "string" && LOCAL_ERROR_CODES.has(value) ? value : "unknown_error";
|
|
54
|
+
}
|
|
55
|
+
function safeInteger(value, min, max) {
|
|
56
|
+
return typeof value === "number" && Number.isInteger(value) && value >= min && value <= max
|
|
57
|
+
? value
|
|
58
|
+
: undefined;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Central operational metadata allowlist.
|
|
62
|
+
*
|
|
63
|
+
* Callers may pass arbitrary objects for backwards compatibility, but only
|
|
64
|
+
* bounded protocol/runtime facts can cross the logging boundary. Dynamic
|
|
65
|
+
* paths, identifiers, user agents, emails, provider bodies, and nested objects
|
|
66
|
+
* are intentionally discarded.
|
|
67
|
+
*/
|
|
68
|
+
function sanitizeMetadata(metadata) {
|
|
69
|
+
if (!metadata)
|
|
70
|
+
return undefined;
|
|
71
|
+
const safe = {};
|
|
72
|
+
const version = typeof metadata.version === "string" && PACKAGE_VERSION.test(metadata.version)
|
|
73
|
+
? metadata.version
|
|
74
|
+
: undefined;
|
|
75
|
+
const transport = typeof metadata.transport === "string" && SAFE_TRANSPORTS.has(metadata.transport)
|
|
76
|
+
? metadata.transport
|
|
77
|
+
: undefined;
|
|
78
|
+
const mcpVersion = typeof metadata.mcpVersion === "string" && SAFE_MCP_VERSIONS.has(metadata.mcpVersion)
|
|
79
|
+
? metadata.mcpVersion
|
|
80
|
+
: undefined;
|
|
81
|
+
const method = typeof metadata.method === "string" && SAFE_METHODS.has(metadata.method)
|
|
82
|
+
? metadata.method
|
|
83
|
+
: undefined;
|
|
84
|
+
const statusCode = safeInteger(metadata.statusCode, 0, 599);
|
|
85
|
+
const retryCount = safeInteger(metadata.retryCount, 0, 100);
|
|
86
|
+
const delayMs = safeInteger(metadata.delayMs, 0, 86_400_000);
|
|
87
|
+
const uptime = safeInteger(metadata.uptime, 0, Number.MAX_SAFE_INTEGER);
|
|
88
|
+
if (version)
|
|
89
|
+
safe.version = version;
|
|
90
|
+
if (transport)
|
|
91
|
+
safe.transport = transport;
|
|
92
|
+
if (mcpVersion)
|
|
93
|
+
safe.mcpVersion = mcpVersion;
|
|
94
|
+
if (method)
|
|
95
|
+
safe.method = method;
|
|
96
|
+
if (statusCode !== undefined)
|
|
97
|
+
safe.statusCode = statusCode;
|
|
98
|
+
if (retryCount !== undefined)
|
|
99
|
+
safe.retryCount = retryCount;
|
|
100
|
+
if (delayMs !== undefined)
|
|
101
|
+
safe.delayMs = delayMs;
|
|
102
|
+
if (uptime !== undefined)
|
|
103
|
+
safe.uptime = uptime;
|
|
104
|
+
if (typeof metadata.success === "boolean")
|
|
105
|
+
safe.success = metadata.success;
|
|
106
|
+
if (typeof metadata.stub === "boolean")
|
|
107
|
+
safe.stub = metadata.stub;
|
|
108
|
+
return Object.keys(safe).length > 0 ? safe : undefined;
|
|
109
|
+
}
|
|
9
110
|
/**
|
|
10
111
|
* Returns true if debug logging is enabled.
|
|
11
112
|
* Checks env var in Node.js; always false in Workers unless overridden.
|
|
@@ -25,10 +126,41 @@ export function log(entry) {
|
|
|
25
126
|
if (entry.level === "debug" && !isDebugEnabled()) {
|
|
26
127
|
return;
|
|
27
128
|
}
|
|
129
|
+
const operation = typeof entry.operation === "string" && Object.hasOwn(OPERATION_MESSAGES, entry.operation)
|
|
130
|
+
? entry.operation
|
|
131
|
+
: undefined;
|
|
132
|
+
const tool = toolNameToken(entry.tool);
|
|
133
|
+
const durationMs = typeof entry.durationMs === "number"
|
|
134
|
+
&& Number.isFinite(entry.durationMs)
|
|
135
|
+
&& entry.durationMs >= 0
|
|
136
|
+
&& entry.durationMs <= 86_400_000
|
|
137
|
+
? Math.round(entry.durationMs)
|
|
138
|
+
: undefined;
|
|
139
|
+
const errorStatus = safeInteger(entry.error?.statusCode, 0, 599);
|
|
140
|
+
const errorCode = operationalErrorCode(entry.error?.code, errorStatus);
|
|
141
|
+
const metadata = sanitizeMetadata(entry.metadata);
|
|
28
142
|
const full = {
|
|
29
|
-
|
|
143
|
+
level: entry.level,
|
|
144
|
+
message: operation === "tool_call" && entry.level === "error"
|
|
145
|
+
? "MCP tool call failed"
|
|
146
|
+
: operation
|
|
147
|
+
? (OPERATION_MESSAGES[operation] ?? "MCP operational event")
|
|
148
|
+
: "MCP operational event",
|
|
30
149
|
service: "frihet-mcp",
|
|
31
150
|
timestamp: new Date().toISOString(),
|
|
151
|
+
...(tool ? { tool } : {}),
|
|
152
|
+
...(operation ? { operation } : {}),
|
|
153
|
+
...(durationMs !== undefined ? { durationMs } : {}),
|
|
154
|
+
...(entry.error
|
|
155
|
+
? {
|
|
156
|
+
error: {
|
|
157
|
+
message: "MCP operation failed",
|
|
158
|
+
code: errorCode,
|
|
159
|
+
...(errorStatus !== undefined ? { statusCode: errorStatus } : {}),
|
|
160
|
+
},
|
|
161
|
+
}
|
|
162
|
+
: {}),
|
|
163
|
+
...(metadata ? { metadata } : {}),
|
|
32
164
|
};
|
|
33
165
|
// Remove undefined fields for cleaner output
|
|
34
166
|
const cleaned = JSON.stringify(full, (_key, value) => value === undefined ? undefined : value);
|
|
@@ -47,7 +179,7 @@ export function logToolCall(tool, startTime, success, error) {
|
|
|
47
179
|
operation: "tool_call",
|
|
48
180
|
durationMs,
|
|
49
181
|
error: {
|
|
50
|
-
message:
|
|
182
|
+
message: "MCP operation failed",
|
|
51
183
|
code: error.errorCode ?? error.name,
|
|
52
184
|
statusCode: error.statusCode,
|
|
53
185
|
},
|
|
@@ -66,25 +198,25 @@ export function logToolCall(tool, startTime, success, error) {
|
|
|
66
198
|
/**
|
|
67
199
|
* Log an outbound API call with timing.
|
|
68
200
|
*/
|
|
69
|
-
export function logApiCall(method,
|
|
201
|
+
export function logApiCall(method, _path, statusCode, durationMs) {
|
|
70
202
|
const level = statusCode >= 500 ? "error" : statusCode >= 400 ? "warn" : "info";
|
|
71
203
|
log({
|
|
72
204
|
level,
|
|
73
|
-
message:
|
|
205
|
+
message: "MCP API call completed",
|
|
74
206
|
operation: "api_call",
|
|
75
207
|
durationMs,
|
|
76
|
-
metadata: { method,
|
|
208
|
+
metadata: { method, statusCode },
|
|
77
209
|
});
|
|
78
210
|
}
|
|
79
211
|
/**
|
|
80
212
|
* Log a rate-limit retry.
|
|
81
213
|
*/
|
|
82
|
-
export function logRetry(method,
|
|
214
|
+
export function logRetry(method, _path, retryCount, delayMs, delaySource) {
|
|
83
215
|
log({
|
|
84
216
|
level: "warn",
|
|
85
|
-
message:
|
|
217
|
+
message: "MCP API retry scheduled",
|
|
86
218
|
operation: "api_retry",
|
|
87
|
-
metadata: { method,
|
|
219
|
+
metadata: { method, retryCount: retryCount + 1, delayMs, delaySource },
|
|
88
220
|
});
|
|
89
221
|
}
|
|
90
222
|
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Meta Muse Profile for the Frihet MCP Server.
|
|
3
|
+
*
|
|
4
|
+
* Implements the curated 18-tool financial management surface submitted
|
|
5
|
+
* for the Meta Muse Business Application catalog.
|
|
6
|
+
*
|
|
7
|
+
* Requirements:
|
|
8
|
+
* - Curated catalogue: 18 high-value small business & freelancer tools.
|
|
9
|
+
* - Human-in-the-loop: Invoices and financial documents are created strictly in draft status.
|
|
10
|
+
* - Zero unconfirmed destructive actions (no direct AEAT / VeriFactu fiscal submissions).
|
|
11
|
+
* - Standard output redaction for sensitive fields.
|
|
12
|
+
*/
|
|
13
|
+
export declare const MUSE_CANDIDATE_TOOLS: ReadonlySet<string>;
|
|
14
|
+
export declare const MUSE_CANDIDATE_TOOL_COUNT: number;
|
|
15
|
+
export declare const MUSE_INSTRUCTIONS = "Frihet ERP \u2014 natural-language business and financial management for Meta Muse.\nUse get_business_context for complete company health and plan limits.\nQuery and review invoices, expenses, quotes, clients, and products with pagination.\nAll created invoices are drafts. Confirm parameters with the user before creating records.";
|
|
16
|
+
export declare function museToolResult(result: unknown): unknown;
|
|
17
|
+
export declare const MUSE_FORCED_INPUT_VALUES: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
18
|
+
export declare function applyMuseProfile(server: any): void;
|
|
19
|
+
//# sourceMappingURL=muse-profile.d.ts.map
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Meta Muse Profile for the Frihet MCP Server.
|
|
3
|
+
*
|
|
4
|
+
* Implements the curated 18-tool financial management surface submitted
|
|
5
|
+
* for the Meta Muse Business Application catalog.
|
|
6
|
+
*
|
|
7
|
+
* Requirements:
|
|
8
|
+
* - Curated catalogue: 18 high-value small business & freelancer tools.
|
|
9
|
+
* - Human-in-the-loop: Invoices and financial documents are created strictly in draft status.
|
|
10
|
+
* - Zero unconfirmed destructive actions (no direct AEAT / VeriFactu fiscal submissions).
|
|
11
|
+
* - Standard output redaction for sensitive fields.
|
|
12
|
+
*/
|
|
13
|
+
import { deepRedact, redactText } from "./redaction.js";
|
|
14
|
+
export const MUSE_CANDIDATE_TOOLS = new Set([
|
|
15
|
+
"get_business_context",
|
|
16
|
+
"get_monthly_summary",
|
|
17
|
+
"get_quarterly_taxes",
|
|
18
|
+
"list_invoices",
|
|
19
|
+
"get_invoice",
|
|
20
|
+
"search_invoices",
|
|
21
|
+
"list_expenses",
|
|
22
|
+
"get_expense",
|
|
23
|
+
"create_expense",
|
|
24
|
+
"list_clients",
|
|
25
|
+
"get_client",
|
|
26
|
+
"create_client",
|
|
27
|
+
"list_products",
|
|
28
|
+
"get_product",
|
|
29
|
+
"list_quotes",
|
|
30
|
+
"get_quote",
|
|
31
|
+
"create_quote",
|
|
32
|
+
"create_invoice",
|
|
33
|
+
]);
|
|
34
|
+
export const MUSE_CANDIDATE_TOOL_COUNT = MUSE_CANDIDATE_TOOLS.size; // 18
|
|
35
|
+
export const MUSE_INSTRUCTIONS = `Frihet ERP — natural-language business and financial management for Meta Muse.
|
|
36
|
+
Use get_business_context for complete company health and plan limits.
|
|
37
|
+
Query and review invoices, expenses, quotes, clients, and products with pagination.
|
|
38
|
+
All created invoices are drafts. Confirm parameters with the user before creating records.`;
|
|
39
|
+
export function museToolResult(result) {
|
|
40
|
+
if (result === null || typeof result !== "object")
|
|
41
|
+
return result;
|
|
42
|
+
const res = result;
|
|
43
|
+
// Deep-redact structured output if present (in-place deletion of sensitive fields)
|
|
44
|
+
if (res.structuredContent && typeof res.structuredContent === "object") {
|
|
45
|
+
deepRedact(res.structuredContent);
|
|
46
|
+
}
|
|
47
|
+
// Redact text content items
|
|
48
|
+
if (Array.isArray(res.content)) {
|
|
49
|
+
res.content = res.content.map((item) => {
|
|
50
|
+
if (item && typeof item === "object" && "text" in item && typeof item.text === "string") {
|
|
51
|
+
return {
|
|
52
|
+
...item,
|
|
53
|
+
text: redactText(item.text),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return item;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return res;
|
|
60
|
+
}
|
|
61
|
+
export const MUSE_FORCED_INPUT_VALUES = {
|
|
62
|
+
create_invoice: { status: "draft" },
|
|
63
|
+
create_quote: { status: "draft" },
|
|
64
|
+
};
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
66
|
+
export function applyMuseProfile(server) {
|
|
67
|
+
const registerTool = server.registerTool.bind(server);
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
|
+
server.registerTool = (name, config, handler) => {
|
|
70
|
+
if (!MUSE_CANDIDATE_TOOLS.has(name))
|
|
71
|
+
return undefined;
|
|
72
|
+
let description = config.description ?? "";
|
|
73
|
+
let inputSchema = config.inputSchema;
|
|
74
|
+
if (name === "create_invoice") {
|
|
75
|
+
description = `${description} [Meta Muse: Generates an invoice strictly in 'draft' status for human review. No irreversible fiscal submission occurs.]`;
|
|
76
|
+
if (inputSchema && typeof inputSchema === "object" && "status" in inputSchema) {
|
|
77
|
+
const { status: _omittedStatus, ...rest } = inputSchema;
|
|
78
|
+
inputSchema = rest;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else if (name === "create_quote") {
|
|
82
|
+
description = `${description} [Meta Muse: Generates a quote strictly in 'draft' status for human review.]`;
|
|
83
|
+
if (inputSchema && typeof inputSchema === "object" && "status" in inputSchema) {
|
|
84
|
+
const { status: _omittedStatus, ...rest } = inputSchema;
|
|
85
|
+
inputSchema = rest;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return registerTool(name, {
|
|
89
|
+
...config,
|
|
90
|
+
description,
|
|
91
|
+
inputSchema,
|
|
92
|
+
annotations: {
|
|
93
|
+
...config.annotations,
|
|
94
|
+
...(config.annotations?.readOnlyHint !== true ? { destructiveHint: true } : {}),
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
98
|
+
async (...args) => {
|
|
99
|
+
try {
|
|
100
|
+
let input = args[0];
|
|
101
|
+
if (input && typeof input === "object") {
|
|
102
|
+
const forced = MUSE_FORCED_INPUT_VALUES[name];
|
|
103
|
+
if (forced) {
|
|
104
|
+
input = { ...input, ...forced };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const res = await handler(input, ...args.slice(1));
|
|
108
|
+
return museToolResult(res);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return museToolResult({
|
|
112
|
+
isError: true,
|
|
113
|
+
_meta: { "io.frihet/operationOutcomeUnknown": true },
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
// Meta Muse profile intentionally registers 0 raw prompts or dynamic resources
|
|
119
|
+
server.registerResource = () => undefined;
|
|
120
|
+
server.registerPrompt = () => undefined;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=muse-profile.js.map
|
package/dist/observability.d.ts
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Design:
|
|
8
8
|
* - Fail-open: any Langfuse error logs a warning and lets the tool proceed.
|
|
9
|
-
* -
|
|
10
|
-
*
|
|
9
|
+
* - Data minimization: only bounded operational facts cross the telemetry
|
|
10
|
+
* boundary. Tool input/output, arbitrary error text, and user/workspace
|
|
11
|
+
* identity are never serialized.
|
|
11
12
|
* - Fire-and-forget: traces are sent via waitUntil (Workers) or unref'd promise
|
|
12
13
|
* (Node.js) so they never block tool responses.
|
|
13
14
|
*
|
|
@@ -18,6 +19,12 @@
|
|
|
18
19
|
*
|
|
19
20
|
* Docs: https://langfuse.com/docs/api/reference/overview
|
|
20
21
|
*/
|
|
22
|
+
/**
|
|
23
|
+
* Langfuse receives a Basic Authorization header, so its authority is exact.
|
|
24
|
+
* The current product contract documents one hosted origin; arbitrary Frihet
|
|
25
|
+
* subdomains and self-hosted overrides are intentionally not trusted here.
|
|
26
|
+
*/
|
|
27
|
+
export declare function normalizeLangfuseBaseUrl(value: string): string;
|
|
21
28
|
/**
|
|
22
29
|
* Called once from FrihetMCP.init() in the Worker to inject env vars.
|
|
23
30
|
* Not needed in Node.js stdio mode (reads from process.env directly).
|
|
@@ -33,8 +40,6 @@ interface LangfuseSpanBody {
|
|
|
33
40
|
name: string;
|
|
34
41
|
startTime: string;
|
|
35
42
|
endTime: string;
|
|
36
|
-
input?: unknown;
|
|
37
|
-
output?: unknown;
|
|
38
43
|
metadata?: Record<string, unknown>;
|
|
39
44
|
level?: "DEFAULT" | "DEBUG" | "WARNING" | "ERROR";
|
|
40
45
|
statusMessage?: string;
|
|
@@ -43,11 +48,8 @@ interface LangfuseTraceBody {
|
|
|
43
48
|
id: string;
|
|
44
49
|
name: string;
|
|
45
50
|
timestamp: string;
|
|
46
|
-
input?: unknown;
|
|
47
|
-
output?: unknown;
|
|
48
51
|
metadata?: Record<string, unknown>;
|
|
49
52
|
tags?: string[];
|
|
50
|
-
userId?: string;
|
|
51
53
|
}
|
|
52
54
|
interface IngestionBatch {
|
|
53
55
|
batch: Array<{
|
|
@@ -58,8 +60,7 @@ interface IngestionBatch {
|
|
|
58
60
|
}>;
|
|
59
61
|
}
|
|
60
62
|
interface StubMarker {
|
|
61
|
-
|
|
62
|
-
note?: string;
|
|
63
|
+
stub: true;
|
|
63
64
|
}
|
|
64
65
|
/**
|
|
65
66
|
* Inspect a resolved tool output for stub / not-implemented / unavailable
|
|
@@ -79,33 +80,24 @@ interface StubMarker {
|
|
|
79
80
|
*/
|
|
80
81
|
export declare function inspectStubMarker(output: unknown): StubMarker | null;
|
|
81
82
|
interface TraceContext {
|
|
82
|
-
/** User-Agent from MCP client or other client identifier */
|
|
83
|
-
clientName?: string;
|
|
84
83
|
/** MCP protocol version */
|
|
85
84
|
mcpVersion?: string;
|
|
86
|
-
/** Frihet workspace/user ID — will be hashed */
|
|
87
|
-
userId?: string;
|
|
88
85
|
}
|
|
89
86
|
/**
|
|
90
|
-
* Set session-level context
|
|
87
|
+
* Set session-level protocol context. Client identity is intentionally absent.
|
|
91
88
|
* Call once from server init; applies to all subsequent traces.
|
|
92
89
|
*/
|
|
93
90
|
export declare function setTraceContext(ctx: TraceContext): void;
|
|
94
91
|
interface TracePayloadParams {
|
|
95
92
|
toolName: string;
|
|
96
|
-
/** Raw tool input args (redacted before serialization). */
|
|
97
|
-
input: unknown;
|
|
98
|
-
/** Raw tool output (redacted before serialization); ignored when isError. */
|
|
99
|
-
output: unknown;
|
|
100
93
|
isError: boolean;
|
|
101
|
-
|
|
94
|
+
errorClass?: string;
|
|
95
|
+
errorCode?: string;
|
|
96
|
+
statusCode?: number;
|
|
102
97
|
startTime: Date;
|
|
103
98
|
endTime: Date;
|
|
104
99
|
traceId: string;
|
|
105
100
|
spanId: string;
|
|
106
|
-
/** Already-hashed user id, or undefined. */
|
|
107
|
-
userIdHashed?: string;
|
|
108
|
-
clientName?: string;
|
|
109
101
|
mcpVersion?: string;
|
|
110
102
|
/** Fabricated-stub marker, or null on a genuine result. */
|
|
111
103
|
stub: StubMarker | null;
|
|
@@ -113,12 +105,9 @@ interface TracePayloadParams {
|
|
|
113
105
|
/**
|
|
114
106
|
* Builds the Langfuse trace+span ingestion batch for a single tool call.
|
|
115
107
|
*
|
|
116
|
-
* CRITICAL (Trust):
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* external Langfuse service — in ANY profile mode. The tool-call output handed
|
|
120
|
-
* to the user is redacted later (OpenAI mode only); this redacts the trace copy
|
|
121
|
-
* unconditionally. Exported so a test can assert no sensitive value survives.
|
|
108
|
+
* CRITICAL (Trust): this builder is an allowlist. It has no input/output or
|
|
109
|
+
* identity fields and ignores any extra runtime properties a caller supplies.
|
|
110
|
+
* Exported so tests can assert the exact operational shape.
|
|
122
111
|
*/
|
|
123
112
|
export declare function buildTracePayload(p: TracePayloadParams): IngestionBatch;
|
|
124
113
|
/**
|
|
@@ -132,6 +121,6 @@ export declare function buildTracePayload(p: TracePayloadParams): IngestionBatch
|
|
|
132
121
|
* @param fn Async tool handler to wrap
|
|
133
122
|
* @returns Result of fn
|
|
134
123
|
*/
|
|
135
|
-
export declare function traceMCPTool<T>(toolName: string,
|
|
124
|
+
export declare function traceMCPTool<T>(toolName: string, _input: unknown, fn: () => Promise<T>): Promise<T>;
|
|
136
125
|
export {};
|
|
137
126
|
//# sourceMappingURL=observability.d.ts.map
|