TypeScript Framework & SDKs
Relevant source files
The following files were used as context for generating this wiki page:
The TypeScript Framework and SDKs provide the core infrastructure for building and interacting with Speakeasy Functions and the Speakeasy platform. This system includes the @speakeasy-api/functions library for creating Model Context Protocol (MCP) servers and the @gram/sdk for platform interactions within the dashboard.
Speakeasy Functions Framework
The @speakeasy-api/functions library provides a Node.js and TypeScript environment for building Speakeasy Functions. These functions act as MCP servers that expose tools to AI agents. The framework assumes Node.js v22 or later and TypeScript v5.9 or later.
Sources: examples/pylon-basic/CONTRIBUTING.md:3-5, examples/turbopuffer/CONTRIBUTING.md:3-5
Core Components and Tool Registration
The Functions class serves as the main entry point. You register tools by chaining .tool() calls on a Functions instance. Each tool requires a unique name, a Zod-based input schema, and an execution function.
The diagram shows the sequential registration of tools and the components required for a valid tool definition.
Sources: examples/pylon-basic/CONTRIBUTING.md:20-40
Execution Context (ctx)
The execute function receives a context object providing helpers for responses and environment access.
| Method/Property | Description |
|---|---|
ctx.json(data) | Returns a JSON response. |
ctx.text(data) | Returns a plain text response. |
ctx.markdown(data) | Returns a Markdown response. |
ctx.fail(data, opts) | Throws an error response with a status code. |
ctx.env | Provides access to validated environment variables. |
ctx.signal | An AbortSignal for handling request cancellation. |
Sources: examples/pylon-basic/CONTRIBUTING.md:52-96
Environment and Security
The framework manages environment variables through a schema-first approach. Variables must be defined in the envSchema using Zod when instantiating the Functions class. This allows the Speakeasy platform to prompt users for required configuration during MCP server installation.
Request Flow and Tool Invocation
When an agent or user invokes a function, the framework validates the input against the Zod schema before execution.
The sequence diagram illustrates the validation-first execution flow for tool calls.
Sources: examples/pylon-basic/CONTRIBUTING.md:120-135, examples/pylon-basic/CONTRIBUTING.md:214-230
Dashboard SDK Integration
The @gram/sdk is used within the React-based dashboard to interact with the Speakeasy backend. It integrates with @tanstack/react-query for data fetching and state management.
Coding Standards and SDK Usage
- React Query: Developers must use React Query for all server state; manual
useEffectoruseStatefor data fetching is prohibited. - Tool Discovery: Dashboard changes must ensure named resources are searchable via the Command K launcher.
- RBAC: Imperative scope checks use the
useRBAC()hook, while declarative gates use the<RequireScope>component.
Sources: REVIEW.md:95-103, REVIEW.md:144-148
Project Infrastructure
The project utilizes a monorepo structure with specific configurations for TypeScript and local development.
| Tool/Config | Purpose |
|---|---|
tsconfig.json | Configures TypeScript with target: es2022 and module: NodeNext. |
./zero | Script for local development setup, handling Docker and database migrations. |
dev-idp | A local Go server that emulates WorkOS for non-interactive login during development. |
Sources: tsconfig.json:18-39, CONTRIBUTING.md:3-10, CONTRIBUTING.md:79-85
Local Development Architecture
The development environment uses Docker and a custom relay for assistant callbacks.
The diagram displays the relationship between host-based process management and Dockerized runtimes.
Sources: CONTRIBUTING.md:3-20, CONTRIBUTING.md:46-55
Conclusion
The TypeScript Framework & SDKs provide a type-safe, validation-first environment for extending Speakeasy via Functions and building the platform dashboard. By enforcing Zod schemas for inputs and environment variables, the system ensures high reliability for AI-driven tool interactions.