Skip to content

Commit 8212c2c

Browse files
committed
feat: Add function URL to cat-facts MCP server to enable testing HTTP transport
1 parent e51e256 commit 8212c2c

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

examples/servers/cat-facts/lib/cat-facts-mcp-server.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import * as cdk from "aws-cdk-lib";
22
import { Construct } from "constructs";
33
import { NodejsFunction } from "aws-cdk-lib/aws-lambda-nodejs";
4-
import { Code, LayerVersion, Runtime } from "aws-cdk-lib/aws-lambda";
4+
import {
5+
Code,
6+
LayerVersion,
7+
Runtime,
8+
FunctionUrl,
9+
FunctionUrlAuthType,
10+
} from "aws-cdk-lib/aws-lambda";
511
import { LogGroup, RetentionDays } from "aws-cdk-lib/aws-logs";
612
import { Role } from "aws-cdk-lib/aws-iam";
713
import { AwsSolutionsChecks } from "cdk-nag";
@@ -42,7 +48,7 @@ export class CatFactsMcpServer extends cdk.Stack {
4248
removalPolicy: cdk.RemovalPolicy.DESTROY,
4349
});
4450

45-
new NodejsFunction(this, "function", {
51+
const lambdaFunction = new NodejsFunction(this, "function", {
4652
functionName: "mcp-server-cat-facts" + stackNameSuffix,
4753
role: Role.fromRoleName(this, "role", "mcp-lambda-example-servers"),
4854
logGroup,
@@ -70,6 +76,17 @@ export class CatFactsMcpServer extends cdk.Stack {
7076
},
7177
},
7278
});
79+
80+
// URL with AWS IAM authorization for HTTP transport
81+
const functionUrl = new FunctionUrl(this, "FunctionUrl", {
82+
function: lambdaFunction,
83+
authType: FunctionUrlAuthType.AWS_IAM,
84+
});
85+
86+
new cdk.CfnOutput(this, "FunctionUrlOutput", {
87+
value: functionUrl.url,
88+
exportName: `CatFactsServerUrl${stackNameSuffix}`,
89+
});
7390
}
7491
}
7592

0 commit comments

Comments
 (0)