Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/typed-state-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"mcp-lite": major
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor? not sure if we wanna bump to v1

Suggested change
"mcp-lite": major
"mcp-lite": minor

---

Add typed state support to McpServer via generic TConfig parameter, enabling type-safe state access in middleware and handlers.

**Breaking change:** The `ctx.env` property has been removed and replaced with `ctx.state`. Migrate by renaming all `ctx.env` references to `ctx.state`.
11 changes: 6 additions & 5 deletions packages/core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,25 @@ export function getProgressToken(
return undefined;
}

export function createContext(
export function createContext<
TConfig extends { State: unknown } = { State: Record<string, unknown> },
>(
message: JsonRpcMessage,
requestId: JsonRpcId | undefined,
options: CreateContextOptions = {},
): MCPServerContext {
): MCPServerContext<TConfig> {
// Prefer explicit option, otherwise derive from the request message
const progressToken =
options.progressToken !== undefined
? options.progressToken
: getProgressToken(message);

const context: MCPServerContext = {
const context: MCPServerContext<TConfig> = {
request: message,
authInfo: options.authInfo,
requestId,
response: null,
env: {},
state: {},
state: {} as TConfig["State"],
progressToken,
validate: <T>(validator: unknown, input: unknown): T =>
createValidationFunction<T>(validator, input),
Expand Down
Loading
Loading