MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / methodAttrs

Function methodAttrs

apps/cloud/src/mcp/telemetry.ts:137–184  ·  view source on GitHub ↗
(envelope: JsonRpcEnvelope)

Source from the content-addressed store, hash-verified

135 );
136
137const methodAttrs = (envelope: JsonRpcEnvelope): Record<string, unknown> => {
138 const params = envelope.params ?? {};
139 return Match.value(envelope.method).pipe(
140 Match.when("initialize", () =>
141 Option.match(decodeInitializeParams(params), {
142 onNone: () => ({}) as Record<string, unknown>,
143 onSome: (init) => ({
144 ...(init.protocolVersion && { "mcp.client.protocol_version": init.protocolVersion }),
145 ...(init.clientInfo?.name && { "mcp.client.name": init.clientInfo.name }),
146 ...(init.clientInfo?.version && { "mcp.client.version": init.clientInfo.version }),
147 ...(init.clientInfo?.title && { "mcp.client.title": init.clientInfo.title }),
148 "mcp.client.capability.keys": Object.keys(init.capabilities ?? {})
149 .sort()
150 .join(","),
151 }),
152 }),
153 ),
154 Match.when("tools/call", () =>
155 Option.match(decodeNamedParams(params), {
156 onNone: () => ({}) as Record<string, unknown>,
157 onSome: ({ name }) => (name ? { "mcp.tool.name": name } : {}),
158 }),
159 ),
160 Match.whenOr("resources/read", "resources/subscribe", () =>
161 Option.match(decodeUriParams(params), {
162 onNone: () => ({}) as Record<string, unknown>,
163 onSome: ({ uri }) => (uri ? { "mcp.resource.uri": uri } : {}),
164 }),
165 ),
166 Match.when("prompts/get", () =>
167 Option.match(decodeNamedParams(params), {
168 onNone: () => ({}) as Record<string, unknown>,
169 onSome: ({ name }) => (name ? { "mcp.prompt.name": name } : {}),
170 }),
171 ),
172 Match.when("notifications/cancelled", () =>
173 Option.match(decodeCancelledParams(params), {
174 onNone: () => ({}) as Record<string, unknown>,
175 onSome: ({ requestId, reason }) => ({
176 ...(requestId !== undefined && { "mcp.rpc.cancelled_id": String(requestId) }),
177 ...(reason && { "mcp.rpc.cancelled_reason": reason }),
178 }),
179 }),
180 ),
181 Match.option,
182 Option.getOrElse(() => ({}) as Record<string, unknown>),
183 );
184};
185
186const replyAttrs = (envelope: JsonRpcEnvelope): Record<string, unknown> => {
187 if (!envelope.result || envelope.method) return {};

Callers 1

rpcAttrsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected