MCPcopy Create free account
hub / github.com/freecodexyz/free-code / parseUpdates

Function parseUpdates

src/components/messages/UserResourceUpdateMessage.tsx:19–45  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

17
18// Parse resource and polling updates from XML format
19function parseUpdates(text: string): ParsedUpdate[] {
20 const updates: ParsedUpdate[] = [];
21
22 // Match <mcp-resource-update server="..." uri="...">
23 const resourceRegex = /<mcp-resource-update\s+server="([^"]+)"\s+uri="([^"]+)"[^>]*>(?:[\s\S]*?<reason>([^<]+)<\/reason>)?/g;
24 let match;
25 while ((match = resourceRegex.exec(text)) !== null) {
26 updates.push({
27 kind: 'resource',
28 server: match[1] ?? '',
29 target: match[2] ?? '',
30 reason: match[3]
31 });
32 }
33
34 // Match <mcp-polling-update type="tool" server="..." tool="...">
35 const pollingRegex = /<mcp-polling-update\s+type="([^"]+)"\s+server="([^"]+)"\s+tool="([^"]+)"[^>]*>(?:[\s\S]*?<reason>([^<]+)<\/reason>)?/g;
36 while ((match = pollingRegex.exec(text)) !== null) {
37 updates.push({
38 kind: 'polling',
39 server: match[2] ?? '',
40 target: match[3] ?? '',
41 reason: match[4]
42 });
43 }
44 return updates;
45}
46
47// Format URI for display - show just the meaningful part
48function formatUri(uri: string): string {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected