🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(mcp): expose observation scope requirements (#15624)
Lysander Kieselb8973335ccf1
diff --git a/web/src/__tests__/server/mcp-tools-read.servertest.ts b/web/src/__tests__/server/mcp-tools-read.servertest.tsindex e321de936a..4aadcf01e5 100644--- a/web/src/__tests__/server/mcp-tools-read.servertest.ts+++ b/web/src/__tests__/server/mcp-tools-read.servertest.ts@@ -732,6 +732,8 @@ describe("MCP Read Tools", () => {default: boolean;expensive: boolean;sensitive: boolean;+ requiresScope?: boolean;+ scopeRequirement?: string;description?: string;}>;@@ -762,7 +764,13 @@ describe("MCP Read Tools", () => {expect(result.fields.costDetails.type).toBe("map<string, number>");expect(result.fields.input.expensive).toBe(true);expect(result.fields.input.sensitive).toBe(true);+ expect(result.fields.input.requiresScope).toBe(true);+ expect(result.fields.input.scopeRequirement).toMatch(+ /traceId.*id filter.*fromStartTime.*toStartTime/i,+ );+ expect(result.fields.output.requiresScope).toBe(true);expect(result.fields.metadata.expensive).toBe(true);+ expect(result.fields.metadata.requiresScope).toBe(true);expect(result.fields.metadata.description).toContain("truncated to 200 UTF-8 characters per key",);diff --git a/web/src/features/mcp/features/observations/schema.ts b/web/src/features/mcp/features/observations/schema.tsindex 861202cdae..1674b24801 100644--- a/web/src/features/mcp/features/observations/schema.ts+++ b/web/src/features/mcp/features/observations/schema.ts@@ -12,6 +12,8 @@ type ObservationMcpFieldMetadata = {default?: boolean;expensive?: boolean;sensitive?: boolean;+ requiresScope?: boolean;+ scopeRequirement?: string;description?: string;};@@ -33,6 +35,9 @@ type ObservationMcpFieldType =| "string"| "unknown";+const EXPENSIVE_FIELD_SCOPE_REQUIREMENT =+ "Requires traceId, an exact id filter, or both fromStartTime and toStartTime.";+const OBSERVATION_MCP_FIELDS = OBSERVATION_FIELD_GROUPS_PUBLIC_API.flatMap((group) => OBSERVATION_FIELD_GROUP_FIELD_NAMES[group],);@@ -68,12 +73,26 @@ const OBSERVATION_MCP_FIELD_METADATA: Record<completionStartTime: { type: "datetime", nullable: true },createdAt: { type: "datetime" },updatedAt: { type: "datetime" },- input: { type: "unknown", expensive: true, sensitive: true },- output: { type: "unknown", expensive: true, sensitive: true },+ input: {+ type: "unknown",+ expensive: true,+ sensitive: true,+ requiresScope: true,+ scopeRequirement: EXPENSIVE_FIELD_SCOPE_REQUIREMENT,+ },+ output: {+ type: "unknown",+ expensive: true,+ sensitive: true,+ requiresScope: true,+ scopeRequirement: EXPENSIVE_FIELD_SCOPE_REQUIREMENT,+ },metadata: {type: "record",expensive: true,sensitive: true,+ requiresScope: true,+ scopeRequirement: EXPENSIVE_FIELD_SCOPE_REQUIREMENT,description:"Metadata values are truncated to 200 UTF-8 characters per key by default. When requesting metadata explicitly, pass expandMetadataKeys with the keys that may need full values.",},diff --git a/web/src/features/mcp/features/observations/tools/getObservationFieldSchema.ts b/web/src/features/mcp/features/observations/tools/getObservationFieldSchema.tsindex f8a0e05cf8..bb58b26962 100644--- a/web/src/features/mcp/features/observations/tools/getObservationFieldSchema.ts+++ b/web/src/features/mcp/features/observations/tools/getObservationFieldSchema.ts@@ -27,6 +27,12 @@ export const [getObservationFieldSchemaTool, handleGetObservationFieldSchema] =default: Boolean(definition.default),expensive: Boolean(definition.expensive),sensitive: Boolean(definition.sensitive),+ ...(definition.requiresScope+ ? {+ requiresScope: true,+ scopeRequirement: definition.scopeRequirement,+ }+ : {}),...(definition.description? { description: definition.description }: {}),diff --git a/web/src/features/mcp/features/observations/tools/listObservations.ts b/web/src/features/mcp/features/observations/tools/listObservations.tsindex be7b70e4f5..c848df9893 100644--- a/web/src/features/mcp/features/observations/tools/listObservations.ts+++ b/web/src/features/mcp/features/observations/tools/listObservations.ts@@ -318,7 +318,7 @@ export const [listObservationsTool, handleListObservations] = defineTool({"Find and review observations in the current Langfuse project, such as generations, spans, events, agent steps, and tool calls.","Traces consist of observations. Use this tool when the user asks to inspect traces: pass traceId to page through the observations for a specific trace; those observation records are the trace data returned by the API.","Use filters to narrow results by trace, name, type, level, environment, time range, or advanced filter conditions. Results are paginated with an opaque cursor.",- "For metadata filters, first call getObservationFilterMetadataKeys with observationIds, traceId, or a bounded time range, then set the relevant key field in the filter.",+ 'For metadata filters, first inspect metadata on selectively scoped observations by passing traceId, an exact id filter, or both fromStartTime and toStartTime with fields: ["id", "metadata"]. Then use a discovered key in a stringObject filter.',"",'By default this returns compact summary fields. Use fields: ["*"] for the full observation, or pass specific field names to limit the response size.','Important: if you request metadata explicitly, for example fields: ["id", "metadata"], metadata values are truncated to 200 UTF-8 characters per key unless you also pass expandMetadataKeys with the keys that may need full values.',