MCPcopy Create free account
hub / github.com/serverless/examples / invoke

Function invoke

aws-bedrock-agentcore/javascript/mcp-server/test-invoke.js:32–59  ·  view source on GitHub ↗
(method, params, id)

Source from the content-addressed store, hash-verified

30let sessionId = null
31
32async function invoke(method, params, id) {
33 const payload = { jsonrpc: '2.0', method, id }
34 if (params) payload.params = params
35
36 const command = new InvokeAgentRuntimeCommand({
37 agentRuntimeArn: RUNTIME_ARN,
38 qualifier: 'DEFAULT',
39 ...(sessionId ? { runtimeSessionId: sessionId } : {}),
40 payload: Buffer.from(JSON.stringify(payload)),
41 contentType: 'application/json',
42 accept: 'application/json, text/event-stream',
43 })
44
45 const response = await client.send(command)
46
47 // Capture session ID from first response
48 if (!sessionId && response.runtimeSessionId) {
49 sessionId = response.runtimeSessionId
50 }
51
52 // Parse response body
53 const body =
54 typeof response.response === 'string'
55 ? response.response
56 : await streamToString(response.response)
57
58 return JSON.parse(body)
59}
60
61async function streamToString(stream) {
62 if (typeof stream === 'string') return stream

Callers 3

testInitializeFunction · 0.70
testListToolsFunction · 0.70
testCallToolFunction · 0.70

Calls 2

streamToStringFunction · 0.85
sendMethod · 0.45

Tested by

no test coverage detected