Skip to main content
Glama
chrisleekr

MCP Server Boilerplate

by chrisleekr
bedrockRuntime.ts2.35 kB
// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/bedrock/ import { BedrockRuntimeClient, InvokeModelCommand, InvokeModelCommandOutput, } from '@aws-sdk/client-bedrock-runtime'; import { config } from '@/config/manager'; import { loggingContext } from '@/core/server/http/context'; import { getCredentialsForBedrock } from './authentication'; const regionClients: Map<string, BedrockRuntimeClient> = new Map(); export function getBedrockRuntimeClientForRegion(): BedrockRuntimeClient { if (regionClients.has(config.tools.aws.bedrock.region)) { loggingContext.log('info', 'Getting BedrockRuntime client for region', { data: { region: config.tools.aws.bedrock.region }, }); const client = regionClients.get(config.tools.aws.bedrock.region); if (!client) { throw new Error( `BedrockRuntime client for region ${config.tools.aws.bedrock.region} was unexpectedly undefined` ); } return client; } loggingContext.log('info', 'Creating BedrockRuntime client for region', { data: { region: config.tools.aws.bedrock.region }, }); const client = new BedrockRuntimeClient({ region: config.tools.aws.bedrock.region, credentials: getCredentialsForBedrock(), }); regionClients.set(config.tools.aws.bedrock.region, client); return client; } // InvokeModel - https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/bedrock-runtime/command/InvokeModelCommand/ export interface InvokeModelParams { body: string; contentType: string; accept: string; modelId: string; trace: 'ENABLED' | 'DISABLED' | 'ENABLED_FULL'; guardrailIdentifier?: string; guardrailVersion?: string; performanceConfigLatency: 'standard' | 'optimized'; } export function invokeModel( params: InvokeModelParams ): Promise<InvokeModelCommandOutput> { const client = getBedrockRuntimeClientForRegion(); loggingContext.log('info', 'Invoking model', { data: { params }, }); const command = new InvokeModelCommand({ body: params.body, contentType: params.contentType, accept: params.accept, modelId: params.modelId, trace: params.trace, guardrailIdentifier: params.guardrailIdentifier, guardrailVersion: params.guardrailVersion, performanceConfigLatency: params.performanceConfigLatency, }); return client.send(command); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/chrisleekr/mcp-server-boilerplate'

If you have feedback or need assistance with the MCP directory API, please join our Discord server