@shivaedev/mcp 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0 - 2026-11-01
4
+
5
+ ### Changed
6
+
7
+ - Identity operation spans use the `Identity` prefix, including `Identity.resolveSession` and `Identity.betterAuthSession`. Adjust trace queries that used `Platform` or `PlatformRpc` names.
8
+
9
+ ### Breaking
10
+
11
+ - Identity reads `SessionPolicy` from the Effect environment. Import the service from `@shivaedev/identity/server/SessionPolicy.ts` and construct one `Layer.succeed(SessionPolicy, { origin, provider, roles, streamRevalidationInterval })`, omitting optional fields as needed. Replace `SessionPolicy<TSession>` annotations with `SessionPolicy["Service"]`; provider-specific types remain on `SessionProvider<TSession>`. Remove policy arguments from session middleware constructors, `resolveSession`, `withSessionUser`, `permissionLayer`, `permissionRoute`, session lookup, rechecks and stream revalidation; provide the policy Layer to the composed readers. Profiles and provider accounts are decoded at their middleware boundaries from the shared provider.
12
+ - Server's `appHost` `sessions` option accepts that Layer and supplies it to middleware, application routes, sockets and change subscriptions. Wrap the previous policy object in `Layer.succeed(SessionPolicy, policy)`. Remove the session-shape generic from host option and factory types, and remove the policy argument from `hostChanges` and `bearerSocketRpc`.
13
+ - Admin uses identity's `SessionPolicy` directly. Replace `AdminSessions` imports and Layers with the identity service, and provide the policy once through the host instead of separately to admin handlers and documents.
14
+ - MCP's `mcpRoutes` reads `SessionPolicy` from the environment. Remove its `sessions` option and the session-shape generic from `McpOptions`; `betterAuthMcp` now returns `sessions` as a policy Layer, which can be passed to the host or supplied to MCP routes with `HttpRouter.provideRequest(oauth.sessions)` when the host also serves cookie-authenticated RPC.
15
+
16
+ ## 0.2.4 - 2026-11-01
17
+
18
+ ### Changed
19
+
20
+ - Update `@shivaedev/access` from 0.3.4 to 0.3.5.
21
+ - Update `@shivaedev/errors` from 0.4.0 to 0.4.1.
22
+ - Update `@shivaedev/identity` from 0.15.0 to 0.16.0.
23
+
3
24
  ## 0.2.3 - 2026-11-01
4
25
 
5
26
  ### Changed
package/README.md CHANGED
@@ -11,7 +11,6 @@ const routes = mcpRoutes({
11
11
  name: "My app",
12
12
  version: "1",
13
13
  path: "/mcp",
14
- sessions: oauth.sessions,
15
14
  resourceMetadataUrl: oauth.resourceMetadataUrl,
16
15
  audiences: [{ tools: userTools }, { permission: ManageTools.any, tools: adminTools }],
17
16
  });
@@ -72,8 +71,10 @@ The Better Auth adapter is an optional edge module. Add its provider to the auth
72
71
  ```ts
73
72
  import { admin, jwt } from "better-auth/plugins";
74
73
  import { Effect, Layer } from "effect";
74
+ import { HttpRouter } from "effect/http";
75
75
  import { betterAuthMount } from "@shivaedev/identity/server/better-auth/mount.ts";
76
76
  import { trustedOrigins } from "@shivaedev/identity/server/origin.ts";
77
+ import { SessionPolicy } from "@shivaedev/identity/server/SessionPolicy.ts";
77
78
  import { betterAuthMcp, mcpProvider } from "@shivaedev/mcp/adapters/betterAuth.ts";
78
79
  import { mcpRoutes } from "@shivaedev/mcp/routes.ts";
79
80
  import { appHost } from "@shivaedev/server/appHost.ts";
@@ -102,7 +103,7 @@ const application = Effect.gen(function* () {
102
103
  return appHost({
103
104
  group: Api,
104
105
  handlers: Handlers,
105
- sessions: { ...mounted.sessions, origin },
106
+ sessions: Layer.succeed(SessionPolicy, { ...mounted.sessions, origin }),
106
107
  routes: Layer.mergeAll(
107
108
  mounted.routes,
108
109
  oauth.routes,
@@ -110,10 +111,9 @@ const application = Effect.gen(function* () {
110
111
  name: "My app",
111
112
  version: "1",
112
113
  path: "/mcp",
113
- sessions: oauth.sessions,
114
114
  resourceMetadataUrl: oauth.resourceMetadataUrl,
115
115
  audiences: [{ tools: userTools }, { permission: ManageTools.any, tools: adminTools }],
116
- }),
116
+ }).pipe(HttpRouter.provideRequest(oauth.sessions)),
117
117
  ),
118
118
  });
119
119
  });
@@ -121,7 +121,7 @@ const application = Effect.gen(function* () {
121
121
 
122
122
  `authPool`, `Api` and `Handlers` are the application's existing auth database, RPC group and handlers. Run the Better Auth migrations with the OAuth and JWT plugins included. For existing role management, keep the application's existing role plugin and `RoleSet` in this configuration.
123
123
 
124
- The edge adapter verifies access-token signatures, issuer, endpoint audience and `mcp` scope, then loads the current user and the token client's consent through Better Auth. Banned users and clients without consent receive the same unauthorized response as invalid tokens. Identity resolves the stored role on each request. An invalid token receives `401` with a `WWW-Authenticate` protected-resource metadata pointer. The metadata names the authorization server and its discovery endpoint, so a client can start OAuth. MCP bearer credentials are separate from browser session cookies.
124
+ The edge adapter verifies access-token signatures, issuer, endpoint audience and `mcp` scope, then loads the current user and the token client's consent through Better Auth. Banned users and clients without consent receive the same unauthorized response as invalid tokens. Identity resolves the stored role on each request. An invalid token receives `401` with a `WWW-Authenticate` protected-resource metadata pointer. The metadata names the authorization server and its discovery endpoint, so a client can start OAuth. MCP bearer credentials are separate from browser session cookies. Provide the OAuth policy Layer to the MCP routes before merging them with a cookie-authenticated host; this makes the authentication scope explicit.
125
125
 
126
126
  ### Revoke client grants
127
127
 
@@ -159,6 +159,6 @@ pnpm add @shivaedev/mcp effect
159
159
  pnpm add better-auth @better-auth/oauth-provider
160
160
  ```
161
161
 
162
- The OAuth dependencies are optional peers, imported only by `adapters/betterAuth.ts`. Core `routes.ts` also accepts another identity `SessionPolicy` with the same identity and permission semantics.
162
+ The OAuth dependencies are optional peers, imported only by `adapters/betterAuth.ts`. Core `routes.ts` reads identity's `SessionPolicy` from the Effect environment with the same identity and permission semantics. Provide the adapter's `sessions` Layer once through the host, or supply another `SessionPolicy` Layer.
163
163
 
164
164
  The endpoint uses Effect's request-scoped Streamable HTTP transport and MCP `2026-07-28`. Clients must support that protocol; earlier session-based versions and subscription streams are outside this adapter. Endpoint requests do not share registries, identities or MCP sessions.
@@ -1,10 +1,10 @@
1
1
  import { type OAuthOptions, oauthProvider, type Scope } from "@better-auth/oauth-provider";
2
- import { Effect } from "effect";
2
+ import { Effect, Layer } from "effect";
3
3
  import { HttpRouter } from "effect/http";
4
4
  import type { RoleSet } from "@shivaedev/access/roleSet.ts";
5
5
  import { AuthUnavailable } from "@shivaedev/errors/taxonomy.ts";
6
6
  import type { OriginPolicy } from "@shivaedev/identity/server/origin.ts";
7
- import type { SessionPolicy, UserSessionShape } from "@shivaedev/identity/server/session.ts";
7
+ import { SessionPolicy } from "@shivaedev/identity/server/SessionPolicy.ts";
8
8
  import { type JwksSource } from "./bearer.ts";
9
9
  import { type OauthAuth } from "./oauthGrants.ts";
10
10
  export declare function mcpProvider({ resource, scopes, ...options }: Omit<OAuthOptions<Scope[]>, "resources" | "clientRegistrationDefaultResources"> & {
@@ -20,7 +20,7 @@ export declare const betterAuthMcp: (options: {
20
20
  revokeAllClients: (userId: string) => Effect.Effect<void, AuthUnavailable, never>;
21
21
  revokeClient: (userId: string, clientId: string) => Effect.Effect<void, AuthUnavailable, never>;
22
22
  resourceMetadataUrl: string;
23
- routes: import("effect/Layer").Layer<never, never, HttpRouter.HttpRouter | HttpRouter.Request<"Error", import("effect/http/HttpServerError").InternalError> | HttpRouter.Request<"Error", import("effect/http/HttpServerError").RequestParseError> | HttpRouter.Request<"Error", import("effect/http/HttpServerError").RouteNotFound>>;
24
- sessions: SessionPolicy<UserSessionShape>;
23
+ routes: Layer.Layer<never, never, HttpRouter.HttpRouter | HttpRouter.Request<"Error", import("effect/http/HttpServerError").InternalError> | HttpRouter.Request<"Error", import("effect/http/HttpServerError").RequestParseError> | HttpRouter.Request<"Error", import("effect/http/HttpServerError").RouteNotFound>>;
24
+ sessions: Layer.Layer<SessionPolicy, never, never>;
25
25
  }, AuthUnavailable, never>;
26
26
  //# sourceMappingURL=betterAuth.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"betterAuth.d.ts","sourceRoot":"","sources":["../../src/adapters/betterAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,aAAa,EAAmC,KAAK,KAAK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AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAC5E,OAAO,EAAU,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAe,KAAK,SAAS,EAAe,MAAM,kBAAkB,CAAC;AAE5E,wBAAgB,WAAW,CAAC,EAC3B,QAAQ,EACR,MAAgB,EAChB,GAAG,OAAO,EACV,EAAE,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC,EAAE,WAAW,GAAG,oCAAoC,CAAC,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,UAAU,CAC9H,OAAO,aAAa,CACpB,CAEA;AAED,eAAO,MAAM,aAAa;mBACV,SAAS;uBACL,MAAM;oBACT,UAAU;qBACT,YAAY;qBACZ,OAAO;;;;;;;0BAgDvB,CAAC"}
@@ -1,7 +1,8 @@
1
1
  import { oauthProvider, oauthProviderAuthServerMetadata } from "@better-auth/oauth-provider";
2
- import { Effect, Option } from "effect";
2
+ import { Effect, Layer, Option } from "effect";
3
3
  import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
4
4
  import { AuthUnavailable } from "@shivaedev/errors/taxonomy.ts";
5
+ import { SessionPolicy } from "@shivaedev/identity/server/SessionPolicy.ts";
5
6
  import { bearer } from "./bearer.js";
6
7
  import { grantedUser, oauthGrants } from "./oauthGrants.js";
7
8
  export function mcpProvider({ resource, scopes = ["mcp"], ...options }) {
@@ -17,7 +18,7 @@ export const betterAuthMcp = Effect.fn("Mcp.betterAuthMcp")(function* (options)
17
18
  const metadataPath = `/.well-known/oauth-protected-resource${url.pathname}`;
18
19
  const resourceMetadataUrl = new URL(metadataPath, url).href;
19
20
  const verify = bearer(options.jwks ?? config.jwks_uri ?? new URL("/api/auth/jwks", url).href, resource, config.issuer);
20
- const sessions = {
21
+ const sessions = Layer.succeed(SessionPolicy, {
21
22
  origin: options.origin,
22
23
  ...(options.roles === undefined ? {} : { roles: options.roles }),
23
24
  provider: {
@@ -36,7 +37,7 @@ export const betterAuthMcp = Effect.fn("Mcp.betterAuthMcp")(function* (options)
36
37
  return Option.some({ user: { email: user.email, id: user.id, name: user.name, ...(typeof role === "string" ? { role } : {}) } });
37
38
  }),
38
39
  },
39
- };
40
+ });
40
41
  const metadata = oauthProviderAuthServerMetadata(auth);
41
42
  const authorizationMetadata = Effect.fn("Mcp.authorizationMetadata")(function* (request) {
42
43
  const web = yield* HttpServerRequest.toWeb(request);
@@ -1 +1 @@
1
- {"version":3,"file":"betterAuth.js","sourceRoot":"","sources":["../../src/adapters/betterAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,aAAa,EAAE,+BAA+B,EAAc,MAAM,6BAA6B,CAAC;AAC5H,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEhF,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAGhE,OAAO,EAAE,MAAM,EAAmB,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,WAAW,EAAkB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE5E,MAAM,UAAU,WAAW,CAAC,EAC3B,QAAQ,EACR,MAAM,GAAG,CAAC,KAAK,CAAC,EAChB,GAAG,OAAO,EACuG;IAGjH,OAAO,aAAa,CAAC,EAAE,GAAG,OAAO,EAAE,kCAAkC,EAAE,CAAC,QAAQ,CAAC,EAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;AACrH,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,EAAE,CAAC,mBAAmB,CAAC,CAAC,QAAQ,CAAC,EAAE,OAMtE;IACA,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,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C,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;YAClI,CAAC,CAAC;SACH;KACD,CAAC,CAAC;IACH,MAAM,QAAQ,GAAG,+BAA+B,CAAC,IAAI,CAAC,CAAC;IACvD,MAAM,qBAAqB,GAAG,MAAM,CAAC,EAAE,CAAC,2BAA2B,CAAC,CAAC,QAAQ,CAAC,EAAE,OAA4C;QAC3H,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,iBAAiB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACpD,OAAO,kBAAkB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC/E,CAAC,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CACxC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QACnB,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAChB,KAAK,EACL,YAAY,EACZ,kBAAkB,CAAC,UAAU,CAAC,EAAE,uBAAuB,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,kBAAkB,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAClH,CAAC;QACF,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,kDAAkD,EAAE,qBAAqB,CAAC,CAAC;IACrG,CAAC,CAAC,CACF,CAAC;IACF,OAAO,EAAE,GAAG,WAAW,CAAC,IAAI,CAAC,EAAE,mBAAmB,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AACxE,CAAC,CAAC,CAAC"}
@@ -1,7 +1,6 @@
1
1
  import { Effect } from "effect";
2
2
  import { HttpRouter } from "effect/http";
3
3
  import { SessionUser } from "@shivaedev/identity/identity.ts";
4
- import type { UserSessionShape } from "@shivaedev/identity/server/session.ts";
5
4
  import type { McpOptions } from "./routes.ts";
6
- export declare const requestServer: <TSession extends UserSessionShape, E, R>(options: McpOptions<TSession, E, R>) => Effect.Effect<import("effect/http/HttpServerResponse").HttpServerResponse, unknown, import("effect/http/HttpServerRequest").HttpServerRequest | import("effect/Scope").Scope | SessionUser | Exclude<R, HttpRouter.HttpRouter>>;
5
+ export declare const requestServer: <E, R>(options: McpOptions<E, R>) => Effect.Effect<import("effect/http/HttpServerResponse").HttpServerResponse, unknown, import("effect/http/HttpServerRequest").HttpServerRequest | import("effect/Scope").Scope | SessionUser | Exclude<R, HttpRouter.HttpRouter>>;
7
6
  //# sourceMappingURL=requestServer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"requestServer.d.ts","sourceRoot":"","sources":["../src/requestServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAS,MAAM,QAAQ,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,eAAO,MAAM,aAAa,GAA6C,QAAQ,SAAS,gBAAgB,EAAE,CAAC,EAAE,CAAC,yQAS5G,CAAC"}
1
+ {"version":3,"file":"requestServer.d.ts","sourceRoot":"","sources":["../src/requestServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAS,MAAM,QAAQ,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,eAAO,MAAM,aAAa,GAA6C,CAAC,EAAE,CAAC,+PASzE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"requestServer.js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ist/routes.d.ts CHANGED
@@ -2,19 +2,17 @@ import { type Layer } from "effect";
2
2
  import { HttpRouter } from "effect/http";
3
3
  import type { Permission } from "@shivaedev/access/permission.ts";
4
4
  import type { Identity, SessionUser } from "@shivaedev/identity/identity.ts";
5
- import { type SessionPolicy, type UserSessionShape } from "@shivaedev/identity/server/session.ts";
6
5
  export interface Audience<E = never, R = never> {
7
6
  readonly permission?: Permission;
8
7
  readonly tools: Layer.Layer<never, E, R>;
9
8
  }
10
- export interface McpOptions<TSession extends UserSessionShape, E, R> {
9
+ export interface McpOptions<E, R> {
11
10
  readonly allowedOrigins?: readonly string[];
12
11
  readonly audiences: readonly Audience<E, R>[];
13
12
  readonly name: string;
14
13
  readonly path: HttpRouter.PathInput;
15
14
  readonly resourceMetadataUrl: string;
16
- readonly sessions: SessionPolicy<TSession>;
17
15
  readonly version: string;
18
16
  }
19
- export declare function mcpRoutes<TSession extends UserSessionShape, E, R>(options: McpOptions<TSession, E, R>): Layer.Layer<never, never, HttpRouter.HttpRouter | HttpRouter.Request<"Error", unknown> | Exclude<HttpRouter.Request.From<"Requires", Exclude<Exclude<Exclude<R, HttpRouter.HttpRouter>, Identity | SessionUser>, HttpRouter.Provided>>, import("effect/Scope").Scope>>;
17
+ export declare function mcpRoutes<E, R>(options: McpOptions<E, R>): Layer.Layer<never, never, HttpRouter.HttpRouter | HttpRouter.Request<"Error", unknown> | HttpRouter.Request<"Requires", import("@shivaedev/identity/server/SessionPolicy.ts").SessionPolicy> | Exclude<HttpRouter.Request.From<"Requires", Exclude<Exclude<Exclude<R, HttpRouter.HttpRouter>, Identity | SessionUser>, HttpRouter.Provided>>, import("effect/Scope").Scope>>;
20
18
  //# sourceMappingURL=routes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,UAAU,EA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,UAAU,EAAsB,MAAM,aAAa,CAAC;AAE7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAElE,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAI7E,MAAM,WAAW,QAAQ,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,KAAK;IAC7C,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;IACjC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,UAAU,CAAC,CAAC,EAAE,CAAC;IAC/B,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C,QAAQ,CAAC,SAAS,EAAE,SAAS,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IAC9C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC;IACpC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CACzB;AAaD,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,gXAaxD"}
package/dist/routes.js CHANGED
@@ -15,7 +15,7 @@ function rejection(error, metadataUrl) {
15
15
  }
16
16
  export function mcpRoutes(options) {
17
17
  const server = requestServer(options);
18
- return HttpRouter.use((router) => router.add("*", options.path, (request) => Effect.context().pipe(withSessionUser(options.sessions, request.headers, request.url), Effect.matchEffect({
18
+ return HttpRouter.use((router) => router.add("*", options.path, (request) => Effect.context().pipe(withSessionUser(request.headers, request.url), Effect.matchEffect({
19
19
  onFailure: (error) => Effect.succeed(rejection(error, options.resourceMetadataUrl)),
20
20
  onSuccess: (context) => Effect.provideContext(server, context),
21
21
  }))));
@@ -1 +1 @@
1
- {"version":3,"file":"routes.js","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAc,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAIrD,OAAO,EAA6C,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACnH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAiBnD,SAAS,SAAS,CAAC,KAAiD,EAAE,WAAmB;IACxF,OAAO,kBAAkB,CAAC,KAAK,CAAC;QAC/B,OAAO,EAAE,KAAK,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,UAAU,EAAE,kBAAkB,EAAE,6BAA6B,WAAW,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE;QAC9I,MAAM,EAAE;YACP,eAAe,EAAE,UAAU,CAAC,WAAW,CAAC,oBAAoB,CAAC;YAC7D,SAAS,EAAE,UAAU,CAAC,WAAW,CAAC,WAAW,CAAC;YAC9C,YAAY,EAAE,UAAU,CAAC,WAAW,CAAC,cAAc,CAAC;SACpD,CAAC,KAAK,CAAC,IAAI,CAAC;KACb,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,SAAS,CAA0C,OAAmC;IACrG,MAAM,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IACtC,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAChC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CACzC,MAAM,CAAC,OAAO,EAA0B,CAAC,IAAI,CAC5C,eAAe,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,CA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IACtC,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAChC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CACzC,MAAM,CAAC,OAAO,EAA0B,CAAC,IAAI,CAC5C,eAAe,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EAC7C,MAAM,CAAC,WAAW,CAAC;QAClB,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;QACnF,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC;KAC9D,CAAC,CACF,CACD,CACD,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivaedev/mcp",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "description": "Identity-aware Effect MCP tools mounted on the application host",
5
5
  "keywords": [
6
6
  "effect"
@@ -43,18 +43,18 @@
43
43
  "README.md"
44
44
  ],
45
45
  "dependencies": {
46
- "@shivaedev/access": "0.3.4",
47
- "@shivaedev/errors": "0.4.0",
48
- "@shivaedev/identity": "0.15.0"
46
+ "@shivaedev/access": "0.3.5",
47
+ "@shivaedev/errors": "0.4.1",
48
+ "@shivaedev/identity": "0.17.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@better-auth/oauth-provider": "1.7.12",
52
52
  "@effect/platform-node": "4.0.6",
53
53
  "@effect/sql-pg": "4.0.6",
54
- "@shivaedev/quality": "0.53.0",
55
- "@shivaedev/server": "0.16.0",
56
- "@shivaedev/test-sql": "0.15.3",
57
- "@shivaedev/test-story": "0.31.3",
54
+ "@shivaedev/quality": "0.54.0",
55
+ "@shivaedev/server": "0.17.0",
56
+ "@shivaedev/test-sql": "0.16.0",
57
+ "@shivaedev/test-story": "0.32.0",
58
58
  "@types/node": "24.19.2",
59
59
  "better-auth": "1.7.12",
60
60
  "effect": "4.0.6",
@@ -1,10 +1,10 @@
1
1
  import { type OAuthOptions, oauthProvider, oauthProviderAuthServerMetadata, type Scope } from "@better-auth/oauth-provider";
2
- import { Effect, Option } from "effect";
2
+ import { Effect, Layer, Option } from "effect";
3
3
  import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http";
4
4
  import type { RoleSet } from "@shivaedev/access/roleSet.ts";
5
5
  import { AuthUnavailable } from "@shivaedev/errors/taxonomy.ts";
6
6
  import type { OriginPolicy } from "@shivaedev/identity/server/origin.ts";
7
- import type { SessionPolicy, UserSessionShape } from "@shivaedev/identity/server/session.ts";
7
+ import { SessionPolicy } from "@shivaedev/identity/server/SessionPolicy.ts";
8
8
  import { bearer, type JwksSource } from "./bearer.ts";
9
9
  import { grantedUser, type OauthAuth, oauthGrants } from "./oauthGrants.ts";
10
10
 
@@ -34,7 +34,7 @@ export const betterAuthMcp = Effect.fn("Mcp.betterAuthMcp")(function* (options:
34
34
  const metadataPath = `/.well-known/oauth-protected-resource${url.pathname}` as const;
35
35
  const resourceMetadataUrl = new URL(metadataPath, url).href;
36
36
  const verify = bearer(options.jwks ?? config.jwks_uri ?? new URL("/api/auth/jwks", url).href, resource, config.issuer);
37
- const sessions: SessionPolicy<UserSessionShape> = {
37
+ const sessions = Layer.succeed(SessionPolicy, {
38
38
  origin: options.origin,
39
39
  ...(options.roles === undefined ? {} : { roles: options.roles }),
40
40
  provider: {
@@ -54,7 +54,7 @@ export const betterAuthMcp = Effect.fn("Mcp.betterAuthMcp")(function* (options:
54
54
  return Option.some({ user: { email: user.email, id: user.id, name: user.name, ...(typeof role === "string" ? { role } : {}) } });
55
55
  }),
56
56
  },
57
- };
57
+ });
58
58
  const metadata = oauthProviderAuthServerMetadata(auth);
59
59
  const authorizationMetadata = Effect.fn("Mcp.authorizationMetadata")(function* (request: HttpServerRequest.HttpServerRequest) {
60
60
  const web = yield* HttpServerRequest.toWeb(request);
@@ -3,10 +3,9 @@ import { McpProtocol, McpServer } from "effect/ai";
3
3
  import { HttpRouter } from "effect/http";
4
4
  import { SessionUser } from "@shivaedev/identity/identity.ts";
5
5
  import { hasPermission } from "@shivaedev/identity/permission.ts";
6
- import type { UserSessionShape } from "@shivaedev/identity/server/session.ts";
7
6
  import type { McpOptions } from "./routes.ts";
8
7
 
9
- export const requestServer = Effect.fn("Mcp.requestServer")(function* <TSession extends UserSessionShape, E, R>(options: McpOptions<TSession, E, R>) {
8
+ export const requestServer = Effect.fn("Mcp.requestServer")(function* <E, R>(options: McpOptions<E, R>) {
10
9
  const user = yield* SessionUser;
11
10
  const inner = yield* HttpRouter.make;
12
11
  const transport = McpServer.layerHttpRequestScoped({ ...options, protocols: [McpProtocol.v2026_07_28] });
package/src/routes.ts CHANGED
@@ -4,7 +4,7 @@ import * as HttpStatus from "effect/http/HttpStatus";
4
4
  import type { Permission } from "@shivaedev/access/permission.ts";
5
5
  import type { AuthUnavailable, Forbidden, Unauthorized } from "@shivaedev/errors/taxonomy.ts";
6
6
  import type { Identity, SessionUser } from "@shivaedev/identity/identity.ts";
7
- import { type SessionPolicy, type UserSessionShape, withSessionUser } from "@shivaedev/identity/server/session.ts";
7
+ import { withSessionUser } from "@shivaedev/identity/server/session.ts";
8
8
  import { requestServer } from "./requestServer.ts";
9
9
 
10
10
  export interface Audience<E = never, R = never> {
@@ -12,13 +12,12 @@ export interface Audience<E = never, R = never> {
12
12
  readonly tools: Layer.Layer<never, E, R>;
13
13
  }
14
14
 
15
- export interface McpOptions<TSession extends UserSessionShape, E, R> {
15
+ export interface McpOptions<E, R> {
16
16
  readonly allowedOrigins?: readonly string[];
17
17
  readonly audiences: readonly Audience<E, R>[];
18
18
  readonly name: string;
19
19
  readonly path: HttpRouter.PathInput;
20
20
  readonly resourceMetadataUrl: string;
21
- readonly sessions: SessionPolicy<TSession>;
22
21
  readonly version: string;
23
22
  }
24
23
 
@@ -33,12 +32,12 @@ function rejection(error: AuthUnavailable | Forbidden | Unauthorized, metadataUr
33
32
  });
34
33
  }
35
34
 
36
- export function mcpRoutes<TSession extends UserSessionShape, E, R>(options: McpOptions<TSession, E, R>) {
35
+ export function mcpRoutes<E, R>(options: McpOptions<E, R>) {
37
36
  const server = requestServer(options);
38
37
  return HttpRouter.use((router) =>
39
38
  router.add("*", options.path, (request) =>
40
39
  Effect.context<Identity | SessionUser>().pipe(
41
- withSessionUser(options.sessions, request.headers, request.url),
40
+ withSessionUser(request.headers, request.url),
42
41
  Effect.matchEffect({
43
42
  onFailure: (error) => Effect.succeed(rejection(error, options.resourceMetadataUrl)),
44
43
  onSuccess: (context) => Effect.provideContext(server, context),