@lynq/lynq 0.3.0 → 0.5.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.
Files changed (54) hide show
  1. package/README.md +88 -12
  2. package/dist/adapters/express.d.ts +7 -2
  3. package/dist/adapters/express.mjs +2 -2
  4. package/dist/adapters/hono.d.ts +7 -2
  5. package/dist/adapters/hono.mjs +1 -1
  6. package/dist/chunk-BVDKAIOU.mjs +1 -0
  7. package/dist/chunk-INAAPNKG.mjs +1 -0
  8. package/dist/chunk-L7SD7KKW.mjs +1 -0
  9. package/dist/chunk-OJJZGR4B.mjs +170 -0
  10. package/dist/chunk-OYHVJKUP.mjs +1 -0
  11. package/dist/chunk-SPZY5GJA.mjs +1 -0
  12. package/dist/index.d.ts +5 -7
  13. package/dist/index.mjs +1 -1
  14. package/dist/middleware/auth.d.ts +6 -8
  15. package/dist/middleware/auth.mjs +1 -1
  16. package/dist/middleware/bearer.d.ts +19 -0
  17. package/dist/middleware/bearer.mjs +1 -0
  18. package/dist/middleware/combine.d.ts +12 -0
  19. package/dist/middleware/combine.mjs +1 -0
  20. package/dist/middleware/credentials.d.ts +19 -0
  21. package/dist/middleware/credentials.mjs +1 -0
  22. package/dist/middleware/crypto.d.ts +64 -0
  23. package/dist/middleware/crypto.mjs +2 -0
  24. package/dist/middleware/github.d.ts +54 -0
  25. package/dist/middleware/github.mjs +2 -0
  26. package/dist/middleware/google.d.ts +55 -0
  27. package/dist/middleware/google.mjs +2 -0
  28. package/dist/middleware/guard.d.ts +15 -0
  29. package/dist/middleware/guard.mjs +1 -0
  30. package/dist/middleware/jwt.d.ts +27 -0
  31. package/dist/middleware/jwt.mjs +1 -0
  32. package/dist/middleware/logger.d.ts +11 -0
  33. package/dist/middleware/logger.mjs +1 -0
  34. package/dist/middleware/oauth.d.ts +28 -0
  35. package/dist/middleware/oauth.mjs +1 -0
  36. package/dist/middleware/payment.d.ts +28 -0
  37. package/dist/middleware/payment.mjs +1 -0
  38. package/dist/middleware/rate-limit.d.ts +15 -0
  39. package/dist/middleware/rate-limit.mjs +1 -0
  40. package/dist/middleware/stripe.d.ts +60 -0
  41. package/dist/middleware/stripe.mjs +1 -0
  42. package/dist/middleware/tip.d.ts +15 -0
  43. package/dist/middleware/tip.mjs +4 -0
  44. package/dist/middleware/truncate.d.ts +13 -0
  45. package/dist/middleware/truncate.mjs +1 -0
  46. package/dist/middleware/url-action.d.ts +30 -0
  47. package/dist/middleware/url-action.mjs +1 -0
  48. package/dist/pages-IPpN74gp.d.ts +26 -0
  49. package/dist/pages-VK55ZBAP.mjs +1 -0
  50. package/dist/store.d.ts +9 -0
  51. package/dist/store.mjs +1 -0
  52. package/dist/test.d.ts +1 -1
  53. package/dist/{types-D504PjnN.d.ts → types-BdFjg9Tn.d.ts} +40 -7
  54. package/package.json +94 -3
@@ -0,0 +1,2 @@
1
+ import {a}from'../chunk-BVDKAIOU.mjs';import'../chunk-OYHVJKUP.mjs';import'../chunk-VAAZWX4U.mjs';function g(e){let{recipient:s,amount:t,token:r="USDC",network:a$1="base",baseUrl:o,callbackPath:n="/payment/crypto/callback",once:p=false}=e,y=e.name??"crypto",m=e.sessionKey??"payment",f=e.message??`Payment required (${t} ${r}).`,i={name:y,sessionKey:m,message:f,buildUrl:({sessionId:c,elicitationId:l})=>{let b=new URLSearchParams({recipient:s,amount:String(t),token:r,network:a$1,state:`${c}:${l}`});return `${o}${n}?${b}`}};e.timeout!==void 0&&(i.timeout=e.timeout),e.skipIf&&(i.skipIf=e.skipIf),e.onComplete&&(i.onComplete=e.onComplete);let u=a(i);return p?u:{...u,onResult(c,l){return l.session.set(m,void 0),c}}}var P=g;async function C(e,s,t){let r=t.sessionKey??"payment",[a,o]=s.state.split(":");if(!a||!o)return {success:false,error:"Invalid state parameter"};try{return await h(s.txHash,t)?(e.session(a).set(r,{provider:"crypto",txHash:s.txHash,amount:t.amount,recipient:t.recipient,paidAt:new Date().toISOString()}),e.completeElicitation(o),{success:!0}):{success:!1,error:"Transaction verification failed"}}catch(n){return {success:false,error:n instanceof Error?n.message:String(n)}}}var x=C;async function h(e,s){let t=s.rpcUrl??"https://mainnet.base.org";try{return (await(await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:1,method:"eth_getTransactionReceipt",params:[e]})})).json()).result?.status==="0x1"}catch{return false}}
2
+ export{g as crypto,C as handleCallback,x as handleUsdcCallback,P as usdcPayment};
@@ -0,0 +1,54 @@
1
+ import { s as ToolContext, v as ToolMiddleware, M as MCPServer } from '../types-BdFjg9Tn.js';
2
+ import '@modelcontextprotocol/sdk/types.js';
3
+ import 'zod';
4
+
5
+ interface GitHubOptions {
6
+ /** Middleware name. Default: "github" */
7
+ name?: string;
8
+ /** GitHub OAuth App client ID. */
9
+ clientId: string;
10
+ /** GitHub OAuth App client secret. */
11
+ clientSecret: string;
12
+ /** OAuth callback URL (your server's callback endpoint). */
13
+ redirectUri: string;
14
+ /** GitHub OAuth scopes. Default: [] */
15
+ scopes?: string[];
16
+ /** Session key for user data. Default: "user" */
17
+ sessionKey?: string;
18
+ /** Message shown to the user. Default: "Please sign in with GitHub to continue." */
19
+ message?: string;
20
+ /** Timeout in ms. Default: 300000 */
21
+ timeout?: number;
22
+ /** Custom skip condition. Takes priority over sessionKey check. */
23
+ skipIf?: (c: ToolContext) => boolean | Promise<boolean>;
24
+ /** Called after authentication completes successfully, before next(). */
25
+ onComplete?: (c: ToolContext) => void | Promise<void>;
26
+ }
27
+ /** @deprecated Use `GitHubOptions` instead. */
28
+ type GitHubOAuthOptions = GitHubOptions;
29
+ declare function github(options: GitHubOptions): ToolMiddleware;
30
+ /** @deprecated Use `github()` from `lynq/github` instead. */
31
+ declare const githubOAuth: typeof github;
32
+ interface HandleCallbackOptions {
33
+ clientId: string;
34
+ clientSecret: string;
35
+ /** Session key for user data. Default: "user" */
36
+ sessionKey?: string;
37
+ }
38
+ /** @deprecated Use `HandleCallbackOptions` instead. */
39
+ type HandleGitHubCallbackOptions = HandleCallbackOptions;
40
+ /**
41
+ * Handle GitHub OAuth callback. Call from your HTTP callback route.
42
+ * Exchanges code for token, fetches user info, stores in session, and completes elicitation.
43
+ */
44
+ declare function handleCallback(server: MCPServer, params: {
45
+ code: string;
46
+ state: string;
47
+ }, options: HandleCallbackOptions): Promise<{
48
+ success: boolean;
49
+ error?: string;
50
+ }>;
51
+ /** @deprecated Use `handleCallback()` from `lynq/github` instead. */
52
+ declare const handleGitHubCallback: typeof handleCallback;
53
+
54
+ export { type GitHubOAuthOptions, type GitHubOptions, type HandleCallbackOptions, type HandleGitHubCallbackOptions, github, githubOAuth, handleCallback, handleGitHubCallback };
@@ -0,0 +1,2 @@
1
+ import {a}from'../chunk-INAAPNKG.mjs';import'../chunk-OYHVJKUP.mjs';import'../chunk-VAAZWX4U.mjs';function p(e){let s=e.scopes??[],t={name:e.name??"github",sessionKey:e.sessionKey??"user",message:e.message??"Please sign in with GitHub to continue.",buildUrl({sessionId:c,elicitationId:n}){let r=new URLSearchParams({client_id:e.clientId,redirect_uri:e.redirectUri,state:`${c}:${n}`});return s.length>0&&r.set("scope",s.join(" ")),`https://github.com/login/oauth/authorize?${r}`}};return e.timeout!==void 0&&(t.timeout=e.timeout),e.skipIf&&(t.skipIf=e.skipIf),e.onComplete&&(t.onComplete=e.onComplete),a(t)}var h=p;async function d(e,s,t){let c=t.sessionKey??"user",[n,r]=s.state.split(":");if(!n||!r)return {success:false,error:"Invalid state parameter"};try{let i=await(await fetch("https://github.com/login/oauth/access_token",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({client_id:t.clientId,client_secret:t.clientSecret,code:s.code})})).json();if(!i.access_token)return {success:!1,error:i.error_description??i.error??"Token exchange failed"};let u=await(await fetch("https://api.github.com/user",{headers:{Authorization:`Bearer ${i.access_token}`}})).json(),a=e.session(n);return a.set(c,u),a.set("accessToken",i.access_token),e.completeElicitation(r),{success:!0}}catch(o){return {success:false,error:o instanceof Error?o.message:String(o)}}}var f=d;
2
+ export{p as github,h as githubOAuth,d as handleCallback,f as handleGitHubCallback};
@@ -0,0 +1,55 @@
1
+ import { s as ToolContext, v as ToolMiddleware, M as MCPServer } from '../types-BdFjg9Tn.js';
2
+ import '@modelcontextprotocol/sdk/types.js';
3
+ import 'zod';
4
+
5
+ interface GoogleOptions {
6
+ /** Middleware name. Default: "google" */
7
+ name?: string;
8
+ /** Google OAuth client ID. */
9
+ clientId: string;
10
+ /** Google OAuth client secret. */
11
+ clientSecret: string;
12
+ /** OAuth callback URL (your server's callback endpoint). */
13
+ redirectUri: string;
14
+ /** OAuth scopes. Default: ["openid", "profile", "email"] */
15
+ scopes?: string[];
16
+ /** Session key for user data. Default: "user" */
17
+ sessionKey?: string;
18
+ /** Message shown to the user. Default: "Please sign in with Google to continue." */
19
+ message?: string;
20
+ /** Timeout in ms. Default: 300000 */
21
+ timeout?: number;
22
+ /** Custom skip condition. Takes priority over sessionKey check. */
23
+ skipIf?: (c: ToolContext) => boolean | Promise<boolean>;
24
+ /** Called after authentication completes successfully, before next(). */
25
+ onComplete?: (c: ToolContext) => void | Promise<void>;
26
+ }
27
+ /** @deprecated Use `GoogleOptions` instead. */
28
+ type GoogleOAuthOptions = GoogleOptions;
29
+ declare function google(options: GoogleOptions): ToolMiddleware;
30
+ /** @deprecated Use `google()` from `lynq/google` instead. */
31
+ declare const googleOAuth: typeof google;
32
+ interface HandleCallbackOptions {
33
+ clientId: string;
34
+ clientSecret: string;
35
+ redirectUri: string;
36
+ /** Session key for user data. Default: "user" */
37
+ sessionKey?: string;
38
+ }
39
+ /** @deprecated Use `HandleCallbackOptions` instead. */
40
+ type HandleGoogleCallbackOptions = HandleCallbackOptions;
41
+ /**
42
+ * Handle Google OAuth callback. Call from your HTTP callback route.
43
+ * Exchanges code for tokens, fetches user info, stores in session, and completes elicitation.
44
+ */
45
+ declare function handleCallback(server: MCPServer, params: {
46
+ code: string;
47
+ state: string;
48
+ }, options: HandleCallbackOptions): Promise<{
49
+ success: boolean;
50
+ error?: string;
51
+ }>;
52
+ /** @deprecated Use `handleCallback()` from `lynq/google` instead. */
53
+ declare const handleGoogleCallback: typeof handleCallback;
54
+
55
+ export { type GoogleOAuthOptions, type GoogleOptions, type HandleCallbackOptions, type HandleGoogleCallbackOptions, google, googleOAuth, handleCallback, handleGoogleCallback };
@@ -0,0 +1,2 @@
1
+ import {a}from'../chunk-INAAPNKG.mjs';import'../chunk-OYHVJKUP.mjs';import'../chunk-VAAZWX4U.mjs';function g(e){let s=e.scopes??["openid","profile","email"],t={name:e.name??"google",sessionKey:e.sessionKey??"user",message:e.message??"Please sign in with Google to continue.",buildUrl({sessionId:i,elicitationId:r}){return `https://accounts.google.com/o/oauth2/v2/auth?${new URLSearchParams({client_id:e.clientId,redirect_uri:e.redirectUri,response_type:"code",scope:s.join(" "),state:`${i}:${r}`,access_type:"offline"})}`}};return e.timeout!==void 0&&(t.timeout=e.timeout),e.skipIf&&(t.skipIf=e.skipIf),e.onComplete&&(t.onComplete=e.onComplete),a(t)}var f=g;async function p(e,s,t){let i=t.sessionKey??"user",[r,c]=s.state.split(":");if(!r||!c)return {success:false,error:"Invalid state parameter"};try{let o=await(await fetch("https://oauth2.googleapis.com/token",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({code:s.code,client_id:t.clientId,client_secret:t.clientSecret,redirect_uri:t.redirectUri,grant_type:"authorization_code"})})).json();if(!o.access_token)return {success:!1,error:o.error_description??o.error??"Token exchange failed"};let d=await(await fetch("https://www.googleapis.com/oauth2/v2/userinfo",{headers:{Authorization:`Bearer ${o.access_token}`}})).json(),a=e.session(r);return a.set(i,d),a.set("accessToken",o.access_token),o.id_token&&a.set("idToken",o.id_token),e.completeElicitation(c),{success:!0}}catch(n){return {success:false,error:n instanceof Error?n.message:String(n)}}}var h=p;
2
+ export{g as google,f as googleOAuth,p as handleCallback,h as handleGoogleCallback};
@@ -0,0 +1,15 @@
1
+ import { v as ToolMiddleware } from '../types-BdFjg9Tn.js';
2
+ import '@modelcontextprotocol/sdk/types.js';
3
+ import 'zod';
4
+
5
+ interface GuardOptions {
6
+ /** Middleware name. Used for authorize()/revoke(). Default: "guard" */
7
+ name?: string;
8
+ /** Session key to check. Default: "user" */
9
+ sessionKey?: string;
10
+ /** Error message when not authorized. */
11
+ message?: string;
12
+ }
13
+ declare function guard(options?: GuardOptions): ToolMiddleware;
14
+
15
+ export { type GuardOptions, guard };
@@ -0,0 +1 @@
1
+ export{a as guard}from'../chunk-L7SD7KKW.mjs';import'../chunk-VAAZWX4U.mjs';
@@ -0,0 +1,27 @@
1
+ import { v as ToolMiddleware } from '../types-BdFjg9Tn.js';
2
+ import '@modelcontextprotocol/sdk/types.js';
3
+ import 'zod';
4
+
5
+ interface JwtOptions {
6
+ /** Middleware name. Default: "jwt" */
7
+ name?: string;
8
+ /** Session key where the raw token is stored. Default: "token" */
9
+ tokenKey?: string;
10
+ /** Session key to store decoded payload. Default: "user" */
11
+ sessionKey?: string;
12
+ /** Symmetric secret for HMAC verification. */
13
+ secret?: string;
14
+ /** JWKS URI for remote key fetching. */
15
+ jwksUri?: string;
16
+ /** Expected issuer claim. */
17
+ issuer?: string;
18
+ /** Expected audience claim. */
19
+ audience?: string;
20
+ /** Additional validation on the decoded payload. Return user data or null. */
21
+ validate?: (payload: Record<string, unknown>) => unknown | null | Promise<unknown | null>;
22
+ /** Error message. Default: "Invalid or expired JWT." */
23
+ message?: string;
24
+ }
25
+ declare function jwt(options: JwtOptions): ToolMiddleware;
26
+
27
+ export { type JwtOptions, jwt };
@@ -0,0 +1 @@
1
+ import {c}from'../chunk-VAAZWX4U.mjs';function j(e){let u=e.name??"jwt",y=e.tokenKey??"token",l=e.sessionKey??"user",d=e.message??"Invalid or expired JWT.",s=null;function m(){return s||(s=import('jose').catch(()=>(s=null,null))),s}return {name:u,onRegister(){return false},async onCall(n,c$1){if(n.session.get(l))return c$1();let a=n.session.get(y);if(!a)return c("JWT required.");let t=await m();if(!t)return c("jose library is required for JWT middleware. Install it: pnpm add jose");try{let i;if(e.jwksUri){let o=t.createRemoteJWKSet(new URL(e.jwksUri));i=(await t.jwtVerify(a,o,{issuer:e.issuer,audience:e.audience})).payload;}else if(e.secret){let o=new TextEncoder().encode(e.secret);i=(await t.jwtVerify(a,o,{issuer:e.issuer,audience:e.audience})).payload;}else return c("JWT middleware misconfigured: provide secret or jwksUri.");let w=e.validate?await e.validate(i):i;return w?(n.session.set(l,w),n.session.authorize(u),c$1()):c(d)}catch{return c(d)}}}}export{j as jwt};
@@ -0,0 +1,11 @@
1
+ import { v as ToolMiddleware } from '../types-BdFjg9Tn.js';
2
+ import '@modelcontextprotocol/sdk/types.js';
3
+ import 'zod';
4
+
5
+ interface LoggerOptions {
6
+ /** Custom log function. Default: console.log */
7
+ log?: (message: string) => void;
8
+ }
9
+ declare function logger(options?: LoggerOptions): ToolMiddleware;
10
+
11
+ export { type LoggerOptions, logger };
@@ -0,0 +1 @@
1
+ function a(s){let e=s?.log??console.log;return {name:"logger",async onCall(o,t){let n=performance.now();e(`[${o.toolName}] called (session: ${o.sessionId})`);let r=await t(),l=(performance.now()-n).toFixed(1);return e(`[${o.toolName}] ${l}ms${r.isError?" ERROR":""}`),r}}}export{a as logger};
@@ -0,0 +1,28 @@
1
+ import { s as ToolContext, v as ToolMiddleware } from '../types-BdFjg9Tn.js';
2
+ import '@modelcontextprotocol/sdk/types.js';
3
+ import 'zod';
4
+
5
+ interface OAuthOptions {
6
+ /** Middleware name. Default: "oauth" */
7
+ name?: string;
8
+ /** Session key for storing tokens. Default: "user" */
9
+ sessionKey?: string;
10
+ /** Message shown to the user. Default: "Please sign in to continue." */
11
+ message?: string;
12
+ /** Build the OAuth authorization URL. */
13
+ buildUrl: (params: {
14
+ sessionId: string;
15
+ elicitationId: string;
16
+ }) => string | Promise<string>;
17
+ /** Timeout in ms. Default: 300000 */
18
+ timeout?: number;
19
+ /** Use persistent store (userStore) instead of session for state. Default: false */
20
+ persistent?: boolean;
21
+ /** Custom skip condition. Takes priority over sessionKey check. */
22
+ skipIf?: (c: ToolContext) => boolean | Promise<boolean>;
23
+ /** Called after authentication completes successfully, before next(). */
24
+ onComplete?: (c: ToolContext) => void | Promise<void>;
25
+ }
26
+ declare function oauth(options: OAuthOptions): ToolMiddleware;
27
+
28
+ export { type OAuthOptions, oauth };
@@ -0,0 +1 @@
1
+ export{a as oauth}from'../chunk-INAAPNKG.mjs';import'../chunk-OYHVJKUP.mjs';import'../chunk-VAAZWX4U.mjs';
@@ -0,0 +1,28 @@
1
+ import { s as ToolContext, v as ToolMiddleware } from '../types-BdFjg9Tn.js';
2
+ import '@modelcontextprotocol/sdk/types.js';
3
+ import 'zod';
4
+
5
+ interface PaymentOptions {
6
+ /** Middleware name. Default: "payment" */
7
+ name?: string;
8
+ /** Session key for storing payment confirmation. Default: "payment" */
9
+ sessionKey?: string;
10
+ /** Message shown to the user. Default: "Please complete payment to continue." */
11
+ message?: string;
12
+ /** Build the payment page URL. */
13
+ buildUrl: (params: {
14
+ sessionId: string;
15
+ elicitationId: string;
16
+ }) => string | Promise<string>;
17
+ /** Timeout in ms. Default: 300000 */
18
+ timeout?: number;
19
+ /** Use persistent store (userStore) instead of session for state. Default: false */
20
+ persistent?: boolean;
21
+ /** Custom skip condition. Takes priority over sessionKey check. */
22
+ skipIf?: (c: ToolContext) => boolean | Promise<boolean>;
23
+ /** Called after payment completes successfully, before next(). */
24
+ onComplete?: (c: ToolContext) => void | Promise<void>;
25
+ }
26
+ declare function payment(options: PaymentOptions): ToolMiddleware;
27
+
28
+ export { type PaymentOptions, payment };
@@ -0,0 +1 @@
1
+ export{a as payment}from'../chunk-BVDKAIOU.mjs';import'../chunk-OYHVJKUP.mjs';import'../chunk-VAAZWX4U.mjs';
@@ -0,0 +1,15 @@
1
+ import { v as ToolMiddleware } from '../types-BdFjg9Tn.js';
2
+ import '@modelcontextprotocol/sdk/types.js';
3
+ import 'zod';
4
+
5
+ interface RateLimitOptions {
6
+ /** Maximum calls per window. */
7
+ max: number;
8
+ /** Window duration in milliseconds. Default: 60000 (1 minute) */
9
+ windowMs?: number;
10
+ /** Error message. */
11
+ message?: string;
12
+ }
13
+ declare function rateLimit(options: RateLimitOptions): ToolMiddleware;
14
+
15
+ export { type RateLimitOptions, rateLimit };
@@ -0,0 +1 @@
1
+ import {c}from'../chunk-VAAZWX4U.mjs';function l(n){let{max:o,windowMs:r=6e4}=n,u=n.message??`Rate limit exceeded. Max ${o} calls per ${r/1e3}s.`;return {name:"rateLimit",async onCall(t,i){let s=`rateLimit:${t.toolName}`,e=t.session.get(s),a=Date.now();return !e||a>=e.resetAt?(t.session.set(s,{count:1,resetAt:a+r}),i()):e.count>=o?c(u):(t.session.set(s,{...e,count:e.count+1}),i())}}}export{l as rateLimit};
@@ -0,0 +1,60 @@
1
+ import { s as ToolContext, M as MCPServer, v as ToolMiddleware } from '../types-BdFjg9Tn.js';
2
+ import '@modelcontextprotocol/sdk/types.js';
3
+ import 'zod';
4
+
5
+ interface StripeOptions {
6
+ /** Middleware name. Default: "stripe" */
7
+ name?: string;
8
+ /** Stripe secret key (server-side). */
9
+ secretKey: string;
10
+ /** Base URL of your server (for callback URLs). */
11
+ baseUrl: string;
12
+ /** Callback path. Default: "/payment/stripe/callback" */
13
+ callbackPath?: string;
14
+ /** Price in cents (USD). e.g., 100 = $1.00 */
15
+ amount: number;
16
+ /** Currency. Default: "usd" */
17
+ currency?: string;
18
+ /** Product description shown on Stripe Checkout. */
19
+ description?: string;
20
+ /** Session key for payment data. Default: "payment" */
21
+ sessionKey?: string;
22
+ /** If true, only charge once per session per tool. Default: false */
23
+ once?: boolean;
24
+ /** Message shown to user. */
25
+ message?: string;
26
+ /** Timeout in ms. Default: 300000 */
27
+ timeout?: number;
28
+ /** Custom skip condition. Takes priority over sessionKey check. */
29
+ skipIf?: (c: ToolContext) => boolean | Promise<boolean>;
30
+ /** Called after payment completes successfully, before next(). */
31
+ onComplete?: (c: ToolContext) => void | Promise<void>;
32
+ }
33
+ /** @deprecated Use `StripeOptions` instead. */
34
+ type StripePaymentOptions = StripeOptions;
35
+ declare function stripe(options: StripeOptions): ToolMiddleware;
36
+ /** @deprecated Use `stripe()` from `lynq/stripe` instead. */
37
+ declare const stripePayment: typeof stripe;
38
+ interface HandleCallbackOptions {
39
+ /** Stripe secret key. */
40
+ secretKey: string;
41
+ /** Session key. Default: "payment" */
42
+ sessionKey?: string;
43
+ }
44
+ /** @deprecated Use `HandleCallbackOptions` instead. */
45
+ type HandleStripeCallbackOptions = HandleCallbackOptions;
46
+ /**
47
+ * Handle Stripe Checkout callback. Call from your HTTP callback route.
48
+ * Retrieves the Checkout Session, verifies payment, stores in session, and completes elicitation.
49
+ */
50
+ declare function handleCallback(server: MCPServer, params: {
51
+ checkoutSessionId: string;
52
+ state: string;
53
+ }, options: HandleCallbackOptions): Promise<{
54
+ success: boolean;
55
+ error?: string;
56
+ }>;
57
+ /** @deprecated Use `handleCallback()` from `lynq/stripe` instead. */
58
+ declare const handleStripeCallback: typeof handleCallback;
59
+
60
+ export { type HandleCallbackOptions, type HandleStripeCallbackOptions, type StripeOptions, type StripePaymentOptions, handleCallback, handleStripeCallback, stripe, stripePayment };
@@ -0,0 +1 @@
1
+ import {a}from'../chunk-BVDKAIOU.mjs';import'../chunk-OYHVJKUP.mjs';import'../chunk-VAAZWX4U.mjs';function S(e){let{secretKey:o,baseUrl:n,callbackPath:a$1="/payment/stripe/callback",amount:r,currency:i="usd",description:t,once:m=false}=e,s=e.name??"stripe",u=e.sessionKey??"payment",b=e.message??`Payment required ($${(r/100).toFixed(2)}).`,c={name:s,sessionKey:u,message:b,async buildUrl({sessionId:l,elicitationId:p}){let g=(await import('stripe')).default,k=new g(o),y=`${l}:${p}`;return (await k.checkout.sessions.create({payment_method_types:["card"],line_items:[{price_data:{currency:i,product_data:{name:t??"Tool access"},unit_amount:r},quantity:1}],mode:"payment",success_url:`${n}${a$1}?session_id={CHECKOUT_SESSION_ID}&state=${y}`,cancel_url:`${n}${a$1}?cancelled=true&state=${y}`,metadata:{sessionId:l,elicitationId:p}})).url??""}};e.timeout!==void 0&&(c.timeout=e.timeout),e.skipIf&&(c.skipIf=e.skipIf),e.onComplete&&(c.onComplete=e.onComplete);let d=a(c);return m?d:{...d,onResult(l,p){return p.session.set(u,void 0),l}}}var x=S;async function C(e,o,n){let a=n.sessionKey??"payment",[r,i]=o.state.split(":");if(!r||!i)return {success:false,error:"Invalid state parameter"};try{let t=(await import('stripe')).default,s=await new t(n.secretKey).checkout.sessions.retrieve(o.checkoutSessionId);return s.payment_status!=="paid"?{success:!1,error:"Payment not completed"}:(e.session(r).set(a,{provider:"stripe",checkoutSessionId:s.id,amount:s.amount_total,currency:s.currency,paidAt:new Date().toISOString()}),e.completeElicitation(i),{success:!0})}catch(t){return {success:false,error:t instanceof Error?t.message:String(t)}}}var P=C;export{C as handleCallback,P as handleStripeCallback,S as stripe,x as stripePayment};
@@ -0,0 +1,15 @@
1
+ import { v as ToolMiddleware } from '../types-BdFjg9Tn.js';
2
+ import '@modelcontextprotocol/sdk/types.js';
3
+ import 'zod';
4
+
5
+ interface TipOptions {
6
+ /** Middleware name. Default: "tip" */
7
+ name?: string;
8
+ /** Build the tip URL. Receives sessionId. */
9
+ url: (sessionId: string) => string;
10
+ /** Message shown to user. Default: "If this was helpful, consider leaving a tip!" */
11
+ message?: string;
12
+ }
13
+ declare function tip(options: TipOptions): ToolMiddleware;
14
+
15
+ export { type TipOptions, tip };
@@ -0,0 +1,4 @@
1
+ function o(t){let n=t.name??"tip",s=t.message??"If this was helpful, consider leaving a tip!";return {name:n,onResult(e,i){if(e.isError)return e;let r=t.url(i.sessionId);return {...e,content:[...e.content??[],{type:"text",text:`
2
+
3
+ ${s}
4
+ ${r}`}]}}}}export{o as tip};
@@ -0,0 +1,13 @@
1
+ import { v as ToolMiddleware } from '../types-BdFjg9Tn.js';
2
+ import '@modelcontextprotocol/sdk/types.js';
3
+ import 'zod';
4
+
5
+ interface TruncateOptions {
6
+ /** Maximum characters per text content block. */
7
+ maxChars: number;
8
+ /** Suffix appended when truncated. Default: "..." */
9
+ suffix?: string;
10
+ }
11
+ declare function truncate(options: TruncateOptions): ToolMiddleware;
12
+
13
+ export { type TruncateOptions, truncate };
@@ -0,0 +1 @@
1
+ function a(e){let{maxChars:r}=e,n=e.suffix??"...";return {name:"truncate",onResult(s){return {...s,content:s.content.map(t=>t.type==="text"&&t.text&&t.text.length>r?{...t,text:t.text.slice(0,r-n.length)+n}:t)}}}}export{a as truncate};
@@ -0,0 +1,30 @@
1
+ import { s as ToolContext, v as ToolMiddleware } from '../types-BdFjg9Tn.js';
2
+ import '@modelcontextprotocol/sdk/types.js';
3
+ import 'zod';
4
+
5
+ interface UrlActionOptions {
6
+ /** Middleware name. Default: "url-action" */
7
+ name?: string;
8
+ /** Session key to check/store result. Default: "user" */
9
+ sessionKey?: string;
10
+ /** Message shown to the user in the elicitation. */
11
+ message: string;
12
+ /** Build the URL. Receives sessionId and elicitationId for callback routing. */
13
+ buildUrl: (params: {
14
+ sessionId: string;
15
+ elicitationId: string;
16
+ }) => string | Promise<string>;
17
+ /** Timeout in ms for waiting for external callback. Default: 300000 (5 min). */
18
+ timeout?: number;
19
+ /** Error message when user declines. Default: "Action cancelled." */
20
+ declineMessage?: string;
21
+ /** Use persistent store (userStore) instead of session for state. Default: false */
22
+ persistent?: boolean;
23
+ /** Custom skip condition. If returns true, skip the elicitation and call next(). Takes priority over sessionKey check. */
24
+ skipIf?: (c: ToolContext) => boolean | Promise<boolean>;
25
+ /** Called after elicitation completes successfully, before next(). */
26
+ onComplete?: (c: ToolContext) => void | Promise<void>;
27
+ }
28
+ declare function urlAction(options: UrlActionOptions): ToolMiddleware;
29
+
30
+ export { type UrlActionOptions, urlAction };
@@ -0,0 +1 @@
1
+ export{a as urlAction}from'../chunk-OYHVJKUP.mjs';import'../chunk-VAAZWX4U.mjs';
@@ -0,0 +1,26 @@
1
+ interface GitHubPagesConfig {
2
+ clientId: string;
3
+ clientSecret: string;
4
+ sessionKey?: string;
5
+ }
6
+ interface GooglePagesConfig {
7
+ clientId: string;
8
+ clientSecret: string;
9
+ sessionKey?: string;
10
+ }
11
+ interface StripePagesConfig {
12
+ secretKey: string;
13
+ sessionKey?: string;
14
+ }
15
+ interface CryptoPagesConfig {
16
+ rpcUrl?: string;
17
+ sessionKey?: string;
18
+ }
19
+ interface PagesConfig {
20
+ github?: true | string | GitHubPagesConfig;
21
+ google?: true | string | GooglePagesConfig;
22
+ stripe?: true | string | StripePagesConfig;
23
+ crypto?: true | string | CryptoPagesConfig;
24
+ }
25
+
26
+ export type { PagesConfig as P };
@@ -0,0 +1 @@
1
+ export{d as cryptoPaymentPage,c as errorPage,a as escapeHtml,h as handleCryptoGet,i as handleCryptoPost,e as handleGitHubPage,f as handleGooglePage,g as handleStripePage,b as successPage}from'./chunk-OJJZGR4B.mjs';
@@ -0,0 +1,9 @@
1
+ import { n as Store, m as Session, U as UserStore } from './types-BdFjg9Tn.js';
2
+ import '@modelcontextprotocol/sdk/types.js';
3
+ import 'zod';
4
+
5
+ declare function memoryStore(): Store;
6
+ declare function resolveUserId(session: Session): string | undefined;
7
+ declare function createUserStore(session: Session, store: Store): UserStore;
8
+
9
+ export { createUserStore, memoryStore, resolveUserId };
package/dist/store.mjs ADDED
@@ -0,0 +1 @@
1
+ export{c as createUserStore,a as memoryStore,b as resolveUserId}from'./chunk-SPZY5GJA.mjs';
package/dist/test.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
2
- import { k as Session, M as MCPServer } from './types-D504PjnN.js';
2
+ import { m as Session, M as MCPServer } from './types-BdFjg9Tn.js';
3
3
  import 'zod';
4
4
 
5
5
  interface TestClient {
@@ -20,6 +20,15 @@ interface ServerInfo {
20
20
  name: string;
21
21
  version: string;
22
22
  }
23
+ interface Store {
24
+ get<T = unknown>(key: string): Promise<T | undefined>;
25
+ set(key: string, value: unknown, ttl?: number): Promise<void>;
26
+ delete(key: string): Promise<void>;
27
+ }
28
+ type UserStore = Store;
29
+ interface ServerOptions extends ServerInfo {
30
+ store?: Store;
31
+ }
23
32
  interface Session {
24
33
  /** Get a session-scoped value. */
25
34
  get<T = unknown>(key: string): T | undefined;
@@ -45,11 +54,19 @@ interface ElicitFormResult<T = Record<string, string | number | boolean | string
45
54
  interface ElicitUrlResult {
46
55
  action: "accept" | "decline" | "cancel";
47
56
  }
57
+ interface ElicitUrlOptions {
58
+ /** Pre-generated elicitation ID. If omitted, a random UUID is used. */
59
+ elicitationId?: string;
60
+ /** If true, wait for completeElicitation() before resolving. Default: false. */
61
+ waitForCompletion?: boolean;
62
+ /** Timeout in ms for waiting. Default: 300000 (5 minutes). */
63
+ timeout?: number;
64
+ }
48
65
  interface Elicit {
49
66
  /** Request structured data from the user via a form. */
50
67
  form<T extends z.ZodObject<z.ZodRawShape>>(message: string, schema: T): Promise<ElicitFormResult<z.infer<T>>>;
51
68
  /** Direct the user to an external URL. */
52
- url(message: string, url: string): Promise<ElicitUrlResult>;
69
+ url(message: string, url: string, options?: ElicitUrlOptions): Promise<ElicitUrlResult>;
53
70
  }
54
71
  interface SampleOptions {
55
72
  maxTokens?: number;
@@ -96,6 +113,10 @@ interface ToolContext {
96
113
  error(message: string): ToolResponse;
97
114
  /** Create an image response. Chainable. */
98
115
  image(data: string, mimeType: string): ToolResponse;
116
+ /** Persistent key-value store (global scope). */
117
+ store: Store;
118
+ /** Persistent key-value store (user scope, keyed by session user ID). */
119
+ userStore: UserStore;
99
120
  }
100
121
  interface ToolInfo {
101
122
  name: string;
@@ -108,16 +129,16 @@ interface ToolMiddleware {
108
129
  /** Called when a tool is registered. Return false to hide the tool initially. */
109
130
  onRegister?(tool: ToolInfo): boolean | undefined;
110
131
  /** Called when a tool is invoked. Must call next() to continue the chain. */
111
- onCall?(ctx: ToolContext, next: () => Promise<CallToolResult>): Promise<CallToolResult>;
132
+ onCall?(c: ToolContext, next: () => Promise<CallToolResult>): Promise<CallToolResult>;
112
133
  /** Called after the handler returns. Runs in reverse middleware order. */
113
- onResult?(result: CallToolResult, ctx: ToolContext): CallToolResult | Promise<CallToolResult>;
134
+ onResult?(result: CallToolResult, c: ToolContext): CallToolResult | Promise<CallToolResult>;
114
135
  }
115
136
  type InferInput<T> = T extends z.ZodTypeAny ? z.output<T> : Record<string, unknown>;
116
137
  interface ToolConfig<TInput = unknown> {
117
138
  description?: string;
118
139
  input?: TInput;
119
140
  }
120
- type ToolHandler<TInput = unknown> = (args: InferInput<TInput>, ctx: ToolContext) => CallToolResult | Promise<CallToolResult>;
141
+ type ToolHandler<TInput = unknown> = (args: InferInput<TInput>, c: ToolContext) => CallToolResult | Promise<CallToolResult>;
121
142
  /** @experimental */
122
143
  interface TaskConfig<TInput = unknown> {
123
144
  description?: string;
@@ -135,7 +156,7 @@ interface TaskContext extends ToolContext {
135
156
  task: TaskControl;
136
157
  }
137
158
  /** @experimental */
138
- type TaskHandler<TInput = unknown> = (args: InferInput<TInput>, ctx: TaskContext) => CallToolResult | Promise<CallToolResult>;
159
+ type TaskHandler<TInput = unknown> = (args: InferInput<TInput>, c: TaskContext) => CallToolResult | Promise<CallToolResult>;
139
160
  interface ResourceConfig {
140
161
  name: string;
141
162
  description?: string;
@@ -152,8 +173,12 @@ interface ResourceContext {
152
173
  sessionId: string;
153
174
  /** Query client-provided filesystem roots. */
154
175
  roots: () => Promise<RootInfo[]>;
176
+ /** Persistent key-value store (global scope). */
177
+ store: Store;
178
+ /** Persistent key-value store (user scope, keyed by session user ID). */
179
+ userStore: UserStore;
155
180
  }
156
- type ResourceHandler = (uri: string, ctx: ResourceContext) => ResourceContent | Promise<ResourceContent>;
181
+ type ResourceHandler = (uri: string, c: ResourceContext) => ResourceContent | Promise<ResourceContent>;
157
182
  interface HttpAdapterOptions {
158
183
  /** Disable session management. Default: false. */
159
184
  sessionless?: boolean;
@@ -161,6 +186,8 @@ interface HttpAdapterOptions {
161
186
  sessionIdGenerator?: () => string;
162
187
  /** Return JSON instead of SSE streams. Default: false. */
163
188
  enableJsonResponse?: boolean;
189
+ /** Called on each HTTP request after session is resolved. Use to inject auth headers into sessions. */
190
+ onRequest?: (req: Request, sessionId: string, session: Session) => void | Promise<void>;
164
191
  }
165
192
  interface MCPServer {
166
193
  /** Register a global middleware applied to all subsequently registered tools. */
@@ -181,6 +208,12 @@ interface MCPServer {
181
208
  stdio(): Promise<void>;
182
209
  /** Start HTTP transport. Returns a Web Standard request handler. */
183
210
  http(options?: HttpAdapterOptions): (req: Request) => Promise<Response>;
211
+ /** Access a session by ID (for external HTTP callback routes). Stateful mode only. */
212
+ session(sessionId: string): Session;
213
+ /** Complete a pending URL elicitation (called from external HTTP callback). */
214
+ completeElicitation(elicitationId: string): void;
215
+ /** The persistent store instance. */
216
+ store: Store;
184
217
  }
185
218
 
186
- export { type Elicit as E, type HttpAdapterOptions as H, type MCPServer as M, type ResourceConfig as R, type Sample as S, type TaskConfig as T, type ElicitFormResult as a, type ElicitUrlResult as b, type ResourceContent as c, type ResourceContext as d, type ResourceHandler as e, type RootInfo as f, type SampleOptions as g, type SampleRawParams as h, type SampleRawResult as i, type ServerInfo as j, type Session as k, type TaskContext as l, type TaskControl as m, type TaskHandler as n, type ToolConfig as o, type ToolContext as p, type ToolHandler as q, type ToolInfo as r, type ToolMiddleware as s, type ToolResponse as t, error as u, image as v, json as w, text as x };
219
+ export { text as A, type Elicit as E, type HttpAdapterOptions as H, type MCPServer as M, type ResourceConfig as R, type ServerOptions as S, type TaskConfig as T, type UserStore as U, type ElicitFormResult as a, type ElicitUrlOptions as b, type ElicitUrlResult as c, type ResourceContent as d, type ResourceContext as e, type ResourceHandler as f, type RootInfo as g, type Sample as h, type SampleOptions as i, type SampleRawParams as j, type SampleRawResult as k, type ServerInfo as l, type Session as m, type Store as n, type TaskContext as o, type TaskControl as p, type TaskHandler as q, type ToolConfig as r, type ToolContext as s, type ToolHandler as t, type ToolInfo as u, type ToolMiddleware as v, type ToolResponse as w, error as x, image as y, json as z };