Skip to content

Add Express + Strands TypeScript chatbot starter (SSE, Zod tools, MCP, interventions) - #309

Open
hsaenzG wants to merge 8 commits into
strands-agents:mainfrom
hsaenzG:feat/express-strands-ts-chatbot-starter
Open

hsaenzG wants to merge 8 commits into
strands-agents:mainfrom
hsaenzG:feat/express-strands-ts-chatbot-starter

Conversation

@hsaenzG

@hsaenzG hsaenzG commented Sep 24, 2026 •

Copy link
Copy Markdown

Summary

Adds a new TypeScript sample: an Express + Strands Agents chatbot starter at typescript/01-learn/07-express-chatbot.

It rebuilds the shape of a typical chatbot service (Node.js, Express, three tools) on the Strands Agents TypeScript SDK, and demonstrates several SDK features together in one runnable service:

  • SSE streaming with event ids — POST /chat/stream forwards every AgentStreamEvent as its own Server-Sent Event with an incrementing id: line (plus a leading session event and a trailing done/error event).
  • Non-streaming route — POST /chat returns the final reply as JSON, plus GET /health.
  • Zod tools — three custom tools (get_current_time, calculate, get_weather) with Zod input schemas.
  • Session store — in-memory per-session conversation history, replayed into the agent each turn.
  • MCP client — connects to an existing remote MCP server over Streamable HTTP and loads its tools alongside the local ones. Defaults to the public, no-auth AWS Knowledge MCP Server, so the agent can search and read official AWS documentation out of the box.
  • Interventions — a rate-limit intervention (beforeToolCall) caps tool calls per session, and a moderation intervention (beforeModelCall) blocks configured terms.

The default model provider is Amazon Bedrock (Amazon Nova Pro). The sample follows the project structure and README template in .github/templates/use-cases/, includes an architecture diagram, and updates the 01-learn index with the new entry.

Project structure

typescript/01-learn/07-express-chatbot/
├── README.md
├── package.json
├── tsconfig.json
├── .env.example
├── images/
│   ├── architecture.png
│   └── architecture.svg
└── src/
    ├── index.ts                          # entry point: env, MCP connect, server start
    ├── server.ts                          # Express app: /health, /chat, /chat/stream (SSE)
    ├── agent.ts                           # per-turn agent factory
    ├── config.ts                          # env-driven configuration
    ├── tools/chatTools.ts                 # three Zod tools
    ├── sessions/SessionStore.ts           # in-memory session store
    ├── mcp/mcpTools.ts                    # MCP client (AWS Knowledge MCP by default)
    ├── interventions/RateLimitIntervention.ts
    ├── interventions/ModerationIntervention.ts
    └── smoke.ts                           # credential-free smoke test

Testing

Verified locally:

  • npm run typecheck (tsc --noEmit) — passes with no errors.
  • npm run smoke — passes: tool registration, moderation (proceed/deny), rate limiting (allow up to cap then deny), and the HTTP layer (400 on empty body, /health ok).
  • Manual run: the server boots, connects to the AWS Knowledge MCP Server and loads its 5 tools, /health returns {"status":"ok"}, and POST /chat/stream emits well-formed SSE frames (id: / event: / data:) starting with the session event. The Bedrock model call requires valid AWS credentials and model access at runtime; failures surface as an SSE error event rather than crashing the process.

Notes

  • Running the chatbot requires AWS credentials in the default credential chain and Bedrock access for the configured model (default us.amazon.nova-pro-v1:0).
  • The MCP integration connects to the public AWS Knowledge MCP Server and needs no credentials; set MCP_SERVER_URL to another Streamable HTTP MCP server, or empty to disable.
  • The moderation intervention uses simple substring matching for illustration and should be replaced with a real moderation service for production use (called out in the README disclaimer).

Tracking

This is a new feature, so there is no GitHub issue to close (no Fixes # applies). Tracked in Asana: https://app.asana.com/1/8442528107068/project/1217155663608611/task/1218296727005011

…, interventions)

New sample at typescript/01-learn/07-express-chatbot: a Node.js + Express
chatbot service on the Strands Agents TypeScript SDK. Includes:

- SSE streaming route with incrementing event ids (POST /chat/stream)
- non-streaming JSON route (POST /chat) and a health check
- three Zod-validated tools (get_current_time, calculate, get_weather)
- an in-memory per-session conversation store
- an optional MCP client that loads server tools at startup
- rate-limit and moderation interventions
- README following the sample template and updated 01-learn index
…re diagram

- Default MCP_SERVER_URL to the public, no-auth AWS Knowledge MCP Server
  (https://knowledge-mcp.global.api.aws) so the agent can search/read AWS docs
  out of the box; config falls back to it and can be disabled by setting it empty.
- Update the MCP module docs and README (overview, features, config, example
  queries, resources) to reflect connecting to an existing remote MCP server.
- Add an architecture diagram (PNG + SVG source) following the style of the
  other TypeScript samples.
…cies

- Switch default Bedrock model from Claude Haiku 4.5 to Amazon Nova Pro
- Update .env.example with new model ID (us.amazon.nova-pro-v1:0)
- Update config.ts default model ID to match
- Refresh package.json dependencies: @strands-agents/sdk to ^1.19.0, express to ^5.1.0, @types/express to ^5.0.0
- Update README prerequisites and configuration table to reflect new default model
- Update architecture diagram and diagram label to show Amazon Nova Pro instead of Claude Haiku 4.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant