avoid workspace state migration

This commit is contained in:
Prasanna A P 2026-07-21 01:06:47 -07:00
parent d26a4d25a8
commit c98a3b59c5
4 changed files with 20 additions and 32 deletions

View file

@ -9,15 +9,14 @@ import { registerProfileResource } from "./resources/profile"
import { registerWidgetResource } from "./resources/widget"
import { registerAllTools } from "./tools"
import { errorResult } from "./tools/types"
import type { WorkspaceState } from "./workspace-state"
type Env = {
MCP_SERVER: DurableObjectNamespace
WORKSPACE_STATE: DurableObjectNamespace<WorkspaceState>
MCP_SERVER: DurableObjectNamespace<SupermemoryMCP>
API_URL?: string
}
const DEFAULT_API_URL = "https://api.supermemory.ai"
const ACTIVE_CONTAINER_TAG_KEY = "activeContainerTag"
export class SupermemoryMCP extends McpAgent<Env, unknown, Props> {
private clientInfo: { name: string; version?: string } | null = null
@ -92,16 +91,28 @@ export class SupermemoryMCP extends McpAgent<Env, unknown, Props> {
}
private workspaceState() {
const key = `${this.props.userId}:${this.props.organizationId ?? "default"}`
return this.env.WORKSPACE_STATE.getByName(key)
const userId = this.props?.userId
if (!userId) throw new Error("Authenticated user ID is required")
const organizationId = this.props?.organizationId ?? "default"
return this.env.MCP_SERVER.getByName(
`workspace-state:${userId}:${organizationId}`,
)
}
private getActiveContainerTag(): Promise<string | undefined> {
return this.workspaceState().getActiveContainerTag()
return this.workspaceState().readActiveContainerTag()
}
private setActiveContainerTag(containerTag: string): Promise<void> {
return this.workspaceState().setActiveContainerTag(containerTag)
return this.workspaceState().writeActiveContainerTag(containerTag)
}
async readActiveContainerTag(): Promise<string | undefined> {
return this.ctx.storage.get<string>(ACTIVE_CONTAINER_TAG_KEY)
}
async writeActiveContainerTag(containerTag: string): Promise<void> {
await this.ctx.storage.put(ACTIVE_CONTAINER_TAG_KEY, containerTag)
}
private getSession() {

View file

@ -4,11 +4,9 @@ import type { ContentfulStatusCode } from "hono/utils/http-status"
import type { Props } from "../shared/types"
import { SupermemoryMCP } from "./agent"
import { validateOAuthToken } from "./auth"
import { WorkspaceState } from "./workspace-state"
type Bindings = {
MCP_SERVER: DurableObjectNamespace
WORKSPACE_STATE: DurableObjectNamespace<WorkspaceState>
MCP_SERVER: DurableObjectNamespace<SupermemoryMCP>
API_URL?: string
MCP_RESOURCE?: string
}
@ -177,6 +175,6 @@ app.all("/mcp/*", async (c) => {
return handleMcpRequest(c)
})
export { SupermemoryMCP, WorkspaceState }
export { SupermemoryMCP }
export default app

View file

@ -1,13 +0,0 @@
import { DurableObject } from "cloudflare:workers"
const ACTIVE_CONTAINER_TAG_KEY = "activeContainerTag"
export class WorkspaceState extends DurableObject {
async getActiveContainerTag(): Promise<string | undefined> {
return this.ctx.storage.get<string>(ACTIVE_CONTAINER_TAG_KEY)
}
async setActiveContainerTag(containerTag: string): Promise<void> {
await this.ctx.storage.put(ACTIVE_CONTAINER_TAG_KEY, containerTag)
}
}

View file

@ -27,10 +27,6 @@
{
"name": "MCP_SERVER",
"class_name": "SupermemoryMCP"
},
{
"name": "WORKSPACE_STATE",
"class_name": "WorkspaceState"
}
]
},
@ -39,10 +35,6 @@
{
"tag": "v1",
"new_sqlite_classes": ["SupermemoryMCP"]
},
{
"tag": "v2",
"new_sqlite_classes": ["WorkspaceState"]
}
],