Documentation
¶
Index ¶
- Constants
- Variables
- func Cors(origins ...string) *scud.Cors
- type Dispatcher
- type DispatcherProps
- type Gateway
- func (c *Gateway) AccessApiKey(access, secret string) *Gateway
- func (c *Gateway) AccessAwsCognito(cognitoArn string, clients ...string) *Gateway
- func (c *Gateway) AccessJWT(issuer string, audience ...string) *Gateway
- func (c *Gateway) AccessLambda(lambda string, props *scud.AuthorizerLambdaProps) *Gateway
- func (c *Gateway) AccessPublic() *Gateway
- func (c *Gateway) Build()
- func (c *Gateway) Cors(origins ...string) *Gateway
- func (c *Gateway) Function(props *awslambda.FunctionProps) *Gateway
- func (c *Gateway) Gateway(props *scud.GatewayProps) *Gateway
- func (c *Gateway) Host(host, certificate string) *Gateway
- func (c *Gateway) Hostless() *Gateway
- func (c *Gateway) Module(module string) *Gateway
- func (c *Gateway) Name(name string) *Gateway
- func (c *Gateway) ResourceMetadata() *Gateway
- func (c *Gateway) Route(route string) *Gateway
- func (c *Gateway) Stack(app awscdk.App) awscdk.Stack
- type Server
- func (c *Server) AllowAccessApiKey(api *scud.AuthorizerBasic) *Server
- func (c *Server) AllowAccessIAM(api *scud.AuthorizerIAM, principal awsiam.IGrantable) *Server
- func (c *Server) AllowAccessJWT(api *scud.AuthorizerJwt, scope ...string) *Server
- func (c *Server) AllowAccessLambda(api *scud.AuthorizerLambda) *Server
- func (c *Server) AllowAccessPublic(api *scud.AuthorizerPublic) *Server
- func (c *Server) ServeResourceMetadata(api *scud.AuthorizerPublic) *Server
- type ServerProps
Constants ¶
const DefaultRoute = "/mcp"
DefaultRoute of MCP server
const MetadataPath = "/.well-known/oauth-protected-resource"
MetadataPath is the well-known path of protected resource metadata.
const Version = "v0.1.0"
Variables ¶
var ( CorsAllowHeaders = []string{ "Authorization", "Content-Type", "Accept", "Mcp-Session-Id", "Mcp-Protocol-Version", "Mcp-Method", "Mcp-Name", "Last-Event-ID", } CorsExposeHeaders = []string{ "Mcp-Session-Id", "Mcp-Protocol-Version", "WWW-Authenticate", } )
Headers of MCP protocol, browser clients send and read them.
var DefaultTimeout = awscdk.Duration_Seconds(jsii.Number(29))
DefaultTimeout of MCP server function, shorter than the API Gateway HTTP API integration timeout (30 seconds).
Functions ¶
Types ¶
type Dispatcher ¶ added in v0.1.0
type Dispatcher struct {
*Server
// contains filtered or unexported fields
}
Dispatcher is L3 construct of MCP server, which lists tools of worker functions and forwards tools/call to them through Lambda Invoke. Workers keep their own IAM roles (least privilege per tool), clients connect to the dispatcher's route only. The dispatcher is a Server, grant access to its route with Allow* methods.
func NewDispatcher ¶ added in v0.1.0
func NewDispatcher(scope constructs.Construct, id *string, props *DispatcherProps) *Dispatcher
NewDispatcher defines the dispatcher function.
func (*Dispatcher) AddWorker ¶ added in v0.1.0
func (d *Dispatcher) AddWorker(worker awslambda.IFunction) *Dispatcher
AddWorker adds the worker function to the dispatcher, granting the dispatcher to invoke it.
type DispatcherProps ¶ added in v0.1.0
type DispatcherProps struct {
// Properties of the dispatcher function (optional).
// The timeout defaults to 29 seconds, it must be shorter than 30 seconds.
*awslambda.FunctionProps
// Implementation name and version reported to clients,
// default is the construct id and the version of cloudmcp.
Name, Version string
// CloudWatch namespace of request metrics (EMF), disabled if empty.
MetricsNamespace string
// Route of the dispatcher, default is /mcp.
Route string
// Payload format of the integration, default is 2.0.
PayloadFormatVersion apigw2.PayloadFormatVersion
// Worker functions running serve.Handler (e.g. serve.Tool).
// Tool names must be unique across workers.
Workers []awslambda.IFunction
}
DispatcherProps defines properties of the dispatcher, the single MCP server aggregating tools of worker functions.
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway is the high-level builder of standalone MCP server deployment: a stack with API Gateway, authorizer and the server function.
cloudmcp.New("cmd/mcp").
Hostless().
AccessApiKey("access", "secret").
Build()
Use NewServer within an existing CDK application instead.
func New ¶
New creates the builder for MCP server, whose main package is at the given path relative to the main module (e.g. "cmd/mcp"). The main is written by the project:
func main() {
lambda.Start(serve.Handler(server.New))
}
func (*Gateway) AccessApiKey ¶
AccessApiKey configures API key access, using basic authentication with access and secret keys.
func (*Gateway) AccessAwsCognito ¶
AccessAwsCognito configures AWS Cognito access, using given user pool ARN and optional list of app clients.
func (*Gateway) AccessJWT ¶
AccessJWT configures JWT access, using given issuer and optional list of audiences.
func (*Gateway) AccessLambda ¶ added in v0.1.0
func (c *Gateway) AccessLambda(lambda string, props *scud.AuthorizerLambdaProps) *Gateway
AccessLambda configures the project's own Lambda authorizer, whose main package is at the given path relative to the module (use package github.com/fogfish/scud/authorizer to implement it).
func (*Gateway) AccessPublic ¶
AccessPublic configures public access (no authentication).
func (*Gateway) Cors ¶ added in v0.1.0
Cors enables CORS for browser MCP clients from the origins, allowing MCP protocol headers.
func (*Gateway) Function ¶ added in v0.1.0
func (c *Gateway) Function(props *awslambda.FunctionProps) *Gateway
Function configures properties of the server function (e.g. memory, environment). The timeout must be shorter than 30 seconds.
func (*Gateway) Gateway ¶
func (c *Gateway) Gateway(props *scud.GatewayProps) *Gateway
Gateway configures gateway with custom properties.
func (*Gateway) Hostless ¶
Hostless configures gateway without custom domain, the default API Gateway host is used.
func (*Gateway) Module ¶ added in v0.1.0
Module of the server's source code, default is the main module of the CDK application.
func (*Gateway) Name ¶ added in v0.1.0
Name of the stack, default is the base name of the server's path. Logs are written to the log group /app/{name}.
func (*Gateway) ResourceMetadata ¶ added in v0.1.0
ResourceMetadata routes protected resource metadata (RFC 9728) to the server as public routes. The server enables it with serve.WithResourceServer.
type Server ¶
type Server struct {
Route string
Function awslambda.Function
// contains filtered or unexported fields
}
Server is L3 construct of MCP server as AWS Lambda function.
func NewServer ¶
func NewServer(scope constructs.Construct, id *string, props *ServerProps) *Server
NewServer defines MCP server as Lambda function.
func (*Server) AllowAccessApiKey ¶
func (c *Server) AllowAccessApiKey(api *scud.AuthorizerBasic) *Server
AllowAccessApiKey grants access to the server via API key authorizer.
func (*Server) AllowAccessIAM ¶
func (c *Server) AllowAccessIAM(api *scud.AuthorizerIAM, principal awsiam.IGrantable) *Server
AllowAccessIAM grants access to the server via IAM authorizer for the principal.
func (*Server) AllowAccessJWT ¶
func (c *Server) AllowAccessJWT(api *scud.AuthorizerJwt, scope ...string) *Server
AllowAccessJWT grants access to the server via JWT (or Cognito) authorizer, requiring the given OAuth scopes.
func (*Server) AllowAccessLambda ¶ added in v0.1.0
func (c *Server) AllowAccessLambda(api *scud.AuthorizerLambda) *Server
AllowAccessLambda grants access to the server via the project's own Lambda authorizer (scud.Gateway.NewAuthorizerLambda). The authorizer's context is available to tools at req.Extra.TokenInfo (see serve.DefaultTokenInfo).
func (*Server) AllowAccessPublic ¶
func (c *Server) AllowAccessPublic(api *scud.AuthorizerPublic) *Server
AllowAccessPublic grants public access to the server.
func (*Server) ServeResourceMetadata ¶ added in v0.1.0
func (c *Server) ServeResourceMetadata(api *scud.AuthorizerPublic) *Server
ServeResourceMetadata routes the protected resource metadata (RFC 9728) to the server as public routes, see serve.WithResourceServer.
type ServerProps ¶
type ServerProps struct {
// The function, built from SourceCodeModule/SourceCodeLambda.
// The timeout defaults to 29 seconds, it must be shorter than 30 seconds.
// The log group and other defaults follow scud.SetDefaults of the scope.
*scud.FunctionGoProps
// Route of the server (e.g. /mcp, /{instance} or /), default is /mcp.
// The route may contain path parameters, they are available to tools at
// req.Extra.TokenInfo.Extra["path"].
Route string
// Payload format of the integration, default is 2.0.
// The function accepts both 1.0 and 2.0.
PayloadFormatVersion apigw2.PayloadFormatVersion
}
ServerProps defines properties of MCP server as Lambda function. The function's main is written by the project:
func main() {
lambda.Start(serve.Handler(server.New))
}
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
dispatcher
command
The dispatcher function deployed by cloudmcp.NewDispatcher.
|
The dispatcher function deployed by cloudmcp.NewDispatcher. |
|
Package dispatch aggregates tools of several worker Lambda functions into one MCP server.
|
Package dispatch aggregates tools of several worker Lambda functions into one MCP server. |
|
examples
|
|
|
helloworld
command
|
|
|
helloworld/lambda
command
Lambda function running the MCP server
|
Lambda function running the MCP server |
|
serverless
command
|
|
|
serverless/cmd/clock
command
Worker function serving the single tool
|
Worker function serving the single tool |
|
serverless/cmd/sayer
command
Worker function serving the single tool
|
Worker function serving the single tool |
|
internal
|
|
|
test/authorizer
command
Lambda authorizer used by tests of constructs
|
Lambda authorizer used by tests of constructs |
|
test/server
command
MCP server function used by tests of constructs
|
MCP server function used by tests of constructs |
|
pkg
|
|
|
auth
module
|
|
|
Package serve is the runtime of cloudmcp.
|
Package serve is the runtime of cloudmcp. |