poe-code 4.0.21 → 4.0.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poe-code",
3
- "version": "4.0.21",
3
+ "version": "4.0.23",
4
4
  "description": "CLI tool to configure Poe API for developer workflows.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -40,7 +40,7 @@ export function createProtectedResourceMetadataRouter(options) {
40
40
  if (path === "/") {
41
41
  return [PROTECTED_RESOURCE_METADATA_PATH];
42
42
  }
43
- return [`${PROTECTED_RESOURCE_METADATA_PATH}${path}`];
43
+ return [PROTECTED_RESOURCE_METADATA_PATH, `${PROTECTED_RESOURCE_METADATA_PATH}${path}`];
44
44
  })();
45
45
  return (req, res, next) => {
46
46
  if (req.method !== "GET" || !metadataPaths.includes(req.path)) {
@@ -14,7 +14,9 @@ export interface TinyHttpMcpServerOAuthOptions extends ProtectedResourceMetadata
14
14
  }
15
15
  export type HttpTransportOptions = ServerOptions & StreamableHttpTransportOptions & {
16
16
  oauth?: TinyHttpMcpServerOAuthOptions;
17
+ requestHandler?: HttpAdditionalRequestHandler;
17
18
  };
19
+ export type HttpAdditionalRequestHandler = (request: IncomingMessage, response: ServerResponse) => boolean | Promise<boolean>;
18
20
  export interface HttpListenOptions {
19
21
  port?: number;
20
22
  hostname?: string;
@@ -19,7 +19,7 @@ function getProtectedResourceMetadataPaths(path) {
19
19
  if (path === "/") {
20
20
  return [PROTECTED_RESOURCE_METADATA_PATH];
21
21
  }
22
- return [`${PROTECTED_RESOURCE_METADATA_PATH}${path}`];
22
+ return [PROTECTED_RESOURCE_METADATA_PATH, `${PROTECTED_RESOURCE_METADATA_PATH}${path}`];
23
23
  }
24
24
  function formatHostnameForUrl(hostname) {
25
25
  if (hostname.includes(":") && !hostname.startsWith("[")) {
@@ -157,6 +157,9 @@ export function createHttpServer(options) {
157
157
  const nodeServer = http.createServer(async (req, res) => {
158
158
  const requestUrl = new URL(req.url ?? "/", "http://127.0.0.1");
159
159
  try {
160
+ if (options.requestHandler !== undefined && (await options.requestHandler(req, res))) {
161
+ return;
162
+ }
160
163
  if (protectedResourceMetadataBody !== undefined &&
161
164
  req.method === "GET" &&
162
165
  getProtectedResourceMetadataPaths(path).includes(requestUrl.pathname)) {
@@ -249,6 +252,9 @@ export function createHttpServer(options) {
249
252
  };
250
253
  };
251
254
  httpServer.handleRequest = async (req, res) => {
255
+ if (options.requestHandler !== undefined && (await options.requestHandler(req, res))) {
256
+ return;
257
+ }
252
258
  const { baseUrl } = req;
253
259
  const protectedResourcePath = typeof baseUrl === "string" && baseUrl.length > 0 ? baseUrl : "/mcp";
254
260
  if (!(await authorizeHttpRequest(req, res, protectedResourcePath))) {
@@ -3,7 +3,7 @@ export type { Server, TypedSchema, ImageContent, AudioContent, EmbeddedResource,
3
3
  export { createExpressMiddleware, createExpressOAuthHandlers, createProtectedResourceMetadataRouter } from "./express-middleware.js";
4
4
  export type { CreateExpressOAuthHandlersOptions } from "./express-middleware.js";
5
5
  export { createHttpServer, createProtectedResourceMetadataDocument } from "./http-server.js";
6
- export type { HttpToolContext, HttpToolHandler, HttpListenOptions, HttpServer, HttpServerHandle, HttpTransportOptions, ProtectedResourceMetadataOptions, TinyHttpMcpServerOAuthOptions } from "./http-server.js";
6
+ export type { HttpToolContext, HttpToolHandler, HttpAdditionalRequestHandler, HttpListenOptions, HttpServer, HttpServerHandle, HttpTransportOptions, ProtectedResourceMetadataOptions, TinyHttpMcpServerOAuthOptions } from "./http-server.js";
7
7
  export { TokenVerificationError } from "./auth.js";
8
8
  export type { RequestAuthInfo, TokenVerifier, VerifiedAccessToken } from "./auth.js";
9
9
  export { StreamableHttpTransport } from "./http-transport.js";
@@ -1,5 +1,5 @@
1
1
  export { createHttpServer, createProtectedResourceMetadataDocument } from "./http-server.js";
2
- export type { HttpToolContext, HttpToolHandler, HttpListenOptions, HttpServer, HttpServerHandle, HttpTransportOptions, ProtectedResourceMetadataOptions, TinyHttpMcpServerOAuthOptions } from "./http-server.js";
2
+ export type { HttpToolContext, HttpToolHandler, HttpAdditionalRequestHandler, HttpListenOptions, HttpServer, HttpServerHandle, HttpTransportOptions, ProtectedResourceMetadataOptions, TinyHttpMcpServerOAuthOptions } from "./http-server.js";
3
3
  export { TokenVerificationError } from "./auth.js";
4
4
  export type { RequestAuthInfo, TokenVerifier, VerifiedAccessToken } from "./auth.js";
5
5
  export { StreamableHttpTransport } from "./http-transport.js";
@@ -0,0 +1,54 @@
1
+ import { hostedOAuth } from "./http-hosted-oauth.js";
2
+ const ignoredHostedOAuth = hostedOAuth({
3
+ publicUrl: "https://calendar.example/mcp",
4
+ storage: ignoredStorage,
5
+ provider: {
6
+ name: "Skylight",
7
+ login: { fields: ["email", "password"] },
8
+ async connect({ email, password, signal }) {
9
+ const ignoredEmail = email;
10
+ const ignoredPassword = password;
11
+ const ignoredSignal = signal;
12
+ return {
13
+ accountId: ignoredEmail,
14
+ credential: `${ignoredPassword}:${ignoredSignal.aborted}`
15
+ };
16
+ },
17
+ services({ credentials, identity }) {
18
+ const ignoredSubject = identity.subject;
19
+ const ignoredClientId = identity.clientId;
20
+ const ignoredScopes = identity.scopes;
21
+ const ignoredResource = identity.resource;
22
+ const ignoredIssuer = identity.issuer;
23
+ void ignoredSubject;
24
+ void ignoredClientId;
25
+ void ignoredScopes;
26
+ void ignoredResource;
27
+ void ignoredIssuer;
28
+ return { skylight: { credential: () => credentials.read() } };
29
+ }
30
+ }
31
+ });
32
+ void ignoredHostedOAuth;
33
+ const ignoredRedirectHostedOAuth = hostedOAuth({
34
+ publicUrl: "https://calendar.example/mcp",
35
+ storage: ignoredStorage,
36
+ provider: {
37
+ name: "Skylight",
38
+ services: ({ credentials }) => ({
39
+ skylight: { credential: () => credentials.read() }
40
+ })
41
+ },
42
+ advanced: {
43
+ interaction: {
44
+ paths: ["/oauth/skylight/callback"],
45
+ start: () => Response.redirect("https://login.example/authorize"),
46
+ handle: async ({ complete }) => complete({
47
+ transactionId: "transaction-id",
48
+ accountId: "account-id",
49
+ credential: "provider-session"
50
+ })
51
+ }
52
+ }
53
+ });
54
+ void ignoredRedirectHostedOAuth;
@@ -0,0 +1,121 @@
1
+ import { type JWK } from "jose";
2
+ import { type AuthorizationServerStore, type AuthorizationTransactionRecord, type OAuthAuthorizationServerSigningKey } from "../../mcp-oauth-server/dist/index.js";
3
+ import type { HttpAdditionalRequestHandler, TinyHttpMcpServerOAuthOptions } from "../../tiny-http-mcp-server/dist/server.js";
4
+ export type HostedOAuthLoginFieldName = "email" | "password" | "apiKey" | (string & {});
5
+ export interface HostedOAuthLoginField {
6
+ name: HostedOAuthLoginFieldName;
7
+ label?: string;
8
+ type?: "text" | "email" | "password";
9
+ }
10
+ export interface HostedOAuthCredentialStore<TCredential = unknown> {
11
+ get(subject: string): Promise<TCredential | undefined>;
12
+ set(subject: string, credential: TCredential): Promise<void>;
13
+ delete(subject: string): Promise<void>;
14
+ update(subject: string, update: (credential: TCredential) => Promise<TCredential> | TCredential): Promise<TCredential>;
15
+ }
16
+ export interface HostedOAuthStorageCapabilities {
17
+ durable: boolean;
18
+ encryptedCredentials: boolean;
19
+ stableKeys: boolean;
20
+ shared: boolean;
21
+ }
22
+ export interface HostedOAuthInteractionStore {
23
+ set(transaction: AuthorizationTransactionRecord): Promise<void>;
24
+ get(transactionId: string): Promise<AuthorizationTransactionRecord | undefined>;
25
+ delete(transactionId: string): Promise<void>;
26
+ }
27
+ export interface HostedOAuthStorage<TCredential = unknown> {
28
+ authorizationServer: AuthorizationServerStore;
29
+ interactions: HostedOAuthInteractionStore;
30
+ credentials: HostedOAuthCredentialStore<TCredential>;
31
+ capabilities: HostedOAuthStorageCapabilities;
32
+ signingKey(): Promise<OAuthAuthorizationServerSigningKey>;
33
+ resolveSubject(providerName: string, accountId: string): Promise<string>;
34
+ cleanup?(now?: number): Promise<void>;
35
+ }
36
+ export interface HostedOAuthCredentialAccess<TCredential = unknown> {
37
+ read(): Promise<TCredential>;
38
+ update(update: (credential: TCredential) => Promise<TCredential> | TCredential): Promise<TCredential>;
39
+ delete(): Promise<void>;
40
+ }
41
+ export interface HostedOAuthIdentity {
42
+ issuer: string;
43
+ subject: string;
44
+ clientId: string;
45
+ scopes: readonly string[];
46
+ resource: string;
47
+ }
48
+ export interface HostedOAuthProvider<TCredential = unknown, TServices extends object = object> {
49
+ name: string;
50
+ login?: {
51
+ fields: readonly (HostedOAuthLoginFieldName | HostedOAuthLoginField)[];
52
+ };
53
+ connect?(fields: Readonly<Record<string, string>> & {
54
+ signal: AbortSignal;
55
+ }): Promise<{
56
+ accountId: string;
57
+ credential: TCredential;
58
+ }>;
59
+ services(input: {
60
+ credentials: HostedOAuthCredentialAccess<TCredential>;
61
+ identity: HostedOAuthIdentity;
62
+ }): Promise<Partial<TServices>> | Partial<TServices>;
63
+ }
64
+ export interface HostedOAuthInteractionAdapter<TCredential = unknown> {
65
+ paths: readonly string[];
66
+ start(context: {
67
+ request: Request;
68
+ transaction: AuthorizationTransactionRecord;
69
+ }): Promise<Response> | Response;
70
+ handle(context: {
71
+ request: Request;
72
+ complete(input: {
73
+ transactionId: string;
74
+ accountId: string;
75
+ credential: TCredential;
76
+ }): Promise<Response>;
77
+ }): Promise<Response> | Response;
78
+ }
79
+ export interface HostedOAuthAdvancedOptions<TCredential = unknown> {
80
+ scopes?: readonly string[];
81
+ branding?: {
82
+ title?: string;
83
+ };
84
+ accessTokenTtlSeconds?: number;
85
+ authorizationCodeTtlSeconds?: number;
86
+ authorizationTransactionTtlSeconds?: number;
87
+ refreshTokenTtlSeconds?: number;
88
+ additionalPublicJwks?: readonly JWK[];
89
+ interaction?: HostedOAuthInteractionAdapter<TCredential>;
90
+ }
91
+ export interface HostedOAuthOptions<TCredential = unknown, TServices extends object = object> {
92
+ publicUrl: string;
93
+ storage: HostedOAuthStorage<TCredential>;
94
+ provider: HostedOAuthProvider<TCredential, TServices>;
95
+ advanced?: HostedOAuthAdvancedOptions<TCredential>;
96
+ }
97
+ export interface PreparedHostedOAuth {
98
+ publicUrl: URL;
99
+ issuer: URL;
100
+ scopes: readonly string[];
101
+ }
102
+ export interface HostedOAuthConfiguration<TCredential = unknown, TServices extends object = object> extends HostedOAuthOptions<TCredential, TServices> {
103
+ readonly kind: "hosted";
104
+ prepare(options?: {
105
+ production?: boolean;
106
+ }): Promise<PreparedHostedOAuth>;
107
+ }
108
+ export declare function isHostedOAuthConfiguration(value: unknown): value is HostedOAuthConfiguration<unknown, object>;
109
+ export declare function hostedOAuth<TCredential = unknown, TServices extends object = object>(options: HostedOAuthOptions<TCredential, TServices>): HostedOAuthConfiguration<TCredential, TServices>;
110
+ export declare class HostedOAuthLoginError extends Error {
111
+ constructor(message: string);
112
+ }
113
+ export interface HostedOAuthRuntime<TServices extends object = object> {
114
+ mcpPath: string;
115
+ oauth: TinyHttpMcpServerOAuthOptions;
116
+ requestHandler: HttpAdditionalRequestHandler;
117
+ requestServices(identity: HostedOAuthIdentity): Promise<Partial<TServices>>;
118
+ }
119
+ export declare function createInMemoryHostedOAuthStorage<TCredential = unknown>(options: {
120
+ development: true;
121
+ }): HostedOAuthStorage<TCredential>;