@forklaunch/core 0.11.4 → 0.11.6
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/lib/http/index.d.mts +24 -8
- package/lib/http/index.d.ts +24 -8
- package/lib/http/index.js +13 -12
- package/lib/http/index.js.map +1 -1
- package/lib/http/index.mjs +13 -12
- package/lib/http/index.mjs.map +1 -1
- package/package.json +4 -4
package/lib/http/index.d.mts
CHANGED
@@ -9,7 +9,7 @@ export { LevelWithSilent, LevelWithSilentOrString, Logger } from 'pino';
|
|
9
9
|
import { JWTPayload } from 'jose';
|
10
10
|
import { Readable } from 'stream';
|
11
11
|
import { ZodSchemaValidator } from '@forklaunch/validator/zod';
|
12
|
-
import {
|
12
|
+
import { FastMCP } from 'fastmcp';
|
13
13
|
import { OpenAPIObject } from 'openapi3-ts/oas31';
|
14
14
|
import { AnyValueMap } from '@opentelemetry/api-logs';
|
15
15
|
import { ApiReferenceConfiguration } from '@scalar/express-api-reference';
|
@@ -818,18 +818,18 @@ interface LiveTypeRouteDefinition<SV extends AnySchemaValidator, BasePath extend
|
|
818
818
|
sdk: object;
|
819
819
|
}> {
|
820
820
|
<Name extends string, Path extends `/${string}`, SuppliedPath extends Path, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>, Auth extends SchemaAuthMethods<SV, P, ReqBody, ReqQuery, ReqHeaders, BaseRequest>>(path: PathMatch<SuppliedPath, Path>, typedHandler: TypedHandler<SV, Name, ContractMethod, Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction, Auth>): ChainableRouter & {
|
821
|
-
fetchMap: Prettify<ChainableRouter['fetchMap'] & Record<SanitizePathSlashes<`${BasePath}${Path}`>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth
|
821
|
+
fetchMap: Prettify<ChainableRouter['fetchMap'] extends Record<SanitizePathSlashes<`${BasePath}${Path}`>, unknown> ? ChainableRouter['fetchMap'] & Record<SanitizePathSlashes<`${BasePath}${Path}`>, ChainableRouter['fetchMap'][SanitizePathSlashes<`${BasePath}${Path}`>] & Record<Uppercase<ContractMethod>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth>>> : ChainableRouter['fetchMap'] & Record<SanitizePathSlashes<`${BasePath}${Path}`>, Record<Uppercase<ContractMethod>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth>>>>;
|
822
822
|
sdk: Prettify<ChainableRouter['sdk'] & Record<PrettyCamelCase<Name>, LiveSdkFunction<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, Auth>>>;
|
823
823
|
};
|
824
824
|
<Name extends string, Path extends `/${string}`, SuppliedPath extends Path, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>, Auth extends SchemaAuthMethods<SV, P, ReqBody, ReqQuery, ReqHeaders, BaseRequest>>(path: PathMatch<SuppliedPath, Path>, middleware: ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction>, ...middlewareAndTypedHandler: [
|
825
825
|
...ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction>[],
|
826
826
|
TypedHandler<SV, Name, ContractMethod, Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction, Auth>
|
827
827
|
]): ChainableRouter & {
|
828
|
-
fetchMap: Prettify<ChainableRouter['fetchMap'] & Record<SanitizePathSlashes<`${BasePath}${Path}`>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth
|
828
|
+
fetchMap: Prettify<ChainableRouter['fetchMap'] extends Record<SanitizePathSlashes<`${BasePath}${Path}`>, unknown> ? ChainableRouter['fetchMap'] & Record<SanitizePathSlashes<`${BasePath}${Path}`>, ChainableRouter['fetchMap'][SanitizePathSlashes<`${BasePath}${Path}`>] & Record<Uppercase<ContractMethod>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth>>> : ChainableRouter['fetchMap'] & Record<SanitizePathSlashes<`${BasePath}${Path}`>, Record<Uppercase<ContractMethod>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth>>>>;
|
829
829
|
sdk: Prettify<ChainableRouter['sdk'] & Record<PrettyCamelCase<Name>, LiveSdkFunction<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, Auth>>>;
|
830
830
|
};
|
831
831
|
<Name extends string, Path extends `/${string}`, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>, Auth extends SchemaAuthMethods<SV, P, ReqBody, ReqQuery, ReqHeaders, BaseRequest>>(path: Path, contractDetails: ContractDetails<SV, Name, ContractMethod, Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, BaseRequest, Auth>, ...middleware: ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction>[]): ChainableRouter & {
|
832
|
-
fetchMap: Prettify<ChainableRouter['fetchMap'] & Record<SanitizePathSlashes<`${BasePath}${Path}`>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth
|
832
|
+
fetchMap: Prettify<ChainableRouter['fetchMap'] extends Record<SanitizePathSlashes<`${BasePath}${Path}`>, unknown> ? ChainableRouter['fetchMap'] & Record<SanitizePathSlashes<`${BasePath}${Path}`>, ChainableRouter['fetchMap'][SanitizePathSlashes<`${BasePath}${Path}`>] & Record<Uppercase<ContractMethod>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth>>> : ChainableRouter['fetchMap'] & Record<SanitizePathSlashes<`${BasePath}${Path}`>, Record<Uppercase<ContractMethod>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth>>>>;
|
833
833
|
sdk: Prettify<ChainableRouter['sdk'] & Record<PrettyCamelCase<Name>, LiveSdkFunction<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, Auth>>>;
|
834
834
|
};
|
835
835
|
}
|
@@ -982,7 +982,7 @@ type MiddlewareOrMiddlewareWithTypedHandler<SV extends AnySchemaValidator, Name
|
|
982
982
|
* });
|
983
983
|
* ```
|
984
984
|
**/
|
985
|
-
type FetchFunction<FetchMap> = <Path extends keyof FetchMap>(path: Path, ...reqInit: FetchMap[Path] extends TypeSafeFunction ? Parameters<FetchMap[Path]>[1] extends {
|
985
|
+
type FetchFunction<FetchMap> = <const Path extends keyof FetchMap, const Method extends keyof FetchMap[Path]>(path: Path, ...reqInit: FetchMap[Path][Method] extends TypeSafeFunction ? 'get' extends keyof FetchMap[Path] ? FetchMap[Path]['get'] extends TypeSafeFunction ? Parameters<FetchMap[Path]['get']>[1] extends {
|
986
986
|
body: unknown;
|
987
987
|
} | {
|
988
988
|
query: unknown;
|
@@ -990,7 +990,23 @@ type FetchFunction<FetchMap> = <Path extends keyof FetchMap>(path: Path, ...reqI
|
|
990
990
|
params: unknown;
|
991
991
|
} | {
|
992
992
|
headers: unknown;
|
993
|
-
} ? [
|
993
|
+
} ? [
|
994
|
+
reqInit: Omit<Parameters<FetchMap[Path][Method]>[1], 'method'> & {
|
995
|
+
method: Method;
|
996
|
+
}
|
997
|
+
] : [
|
998
|
+
reqInit?: Omit<Parameters<FetchMap[Path][Method]>[1], 'method'> & {
|
999
|
+
method: Method;
|
1000
|
+
}
|
1001
|
+
] : [
|
1002
|
+
reqInit: Omit<Parameters<FetchMap[Path][Method]>[1], 'method'> & {
|
1003
|
+
method: Method;
|
1004
|
+
}
|
1005
|
+
] : [
|
1006
|
+
reqInit: Omit<Parameters<FetchMap[Path][Method]>[1], 'method'> & {
|
1007
|
+
method: Method;
|
1008
|
+
}
|
1009
|
+
] : []) => Promise<FetchMap[Path][Method] extends TypeSafeFunction ? ReturnType<FetchMap[Path][Method]> : never>;
|
994
1010
|
/**
|
995
1011
|
* Creates a router SDK by combining the router's SDK with its fetch functionality.
|
996
1012
|
* This type merges the router's SDK interface with its fetch methods to create
|
@@ -1188,7 +1204,7 @@ declare class ForklaunchExpressLikeRouter<SV extends AnySchemaValidator, BasePat
|
|
1188
1204
|
*/
|
1189
1205
|
fetch: FetchFunction<this['fetchMap']>;
|
1190
1206
|
registerRoute<Name extends string, ContractMethod extends Method, Path extends `/${string}`, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>, const Auth extends SchemaAuthMethods<SV, P, ReqBody, ReqQuery, ReqHeaders, BaseRequest>>(method: ContractMethod, path: Path, registrationMethod: PathBasedHandler<RouterHandler>, contractDetailsOrMiddlewareOrTypedHandler: ContractDetailsOrMiddlewareOrTypedHandler<SV, Name, ContractMethod, Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction, Auth>, ...middlewareOrMiddlewareAndTypedHandler: MiddlewareOrMiddlewareWithTypedHandler<SV, Name, ContractMethod, Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction, Auth>[]): this & {
|
1191
|
-
fetchMap: Prettify<FetchMap & Record<SanitizePathSlashes<`${BasePath}${Path}`>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth
|
1207
|
+
fetchMap: Prettify<FetchMap extends Record<SanitizePathSlashes<`${BasePath}${Path}`>, unknown> ? FetchMap & Record<SanitizePathSlashes<`${BasePath}${Path}`>, FetchMap[SanitizePathSlashes<`${BasePath}${Path}`>] & Record<Uppercase<ContractMethod>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth>>> : FetchMap & Record<SanitizePathSlashes<`${BasePath}${Path}`>, Record<Uppercase<ContractMethod>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth>>>>;
|
1192
1208
|
sdk: Prettify<Sdk & Record<PrettyCamelCase<Name extends string ? Name : SanitizePathSlashes<`${BasePath}${Path}`>>, LiveSdkFunction<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, Auth>>>;
|
1193
1209
|
};
|
1194
1210
|
registerMiddlewareHandler<Name extends string, Path extends `/${string}`, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>, const Auth extends SchemaAuthMethods<SV, P, ReqBody, ReqQuery, ReqHeaders, BaseRequest>>(registrationMethod: PathOrMiddlewareBasedHandler<RouterHandler>, pathOrContractDetailsOrMiddlewareOrTypedHandler: Path | ContractDetailsOrMiddlewareOrTypedHandler<SV, Name, 'middleware', Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction, Auth> | RouterHandler, contractDetailsOrMiddlewareOrTypedHandler?: ContractDetailsOrMiddlewareOrTypedHandler<SV, Name, 'middleware', Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction, Auth> | RouterHandler, ...middlewareOrMiddlewareWithTypedHandler: (MiddlewareOrMiddlewareWithTypedHandler<SV, Name, 'middleware', Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction, Auth> | RouterHandler)[]): this;
|
@@ -1499,7 +1515,7 @@ declare const getCodeForStatus: (status: string) => null | StatusCode;
|
|
1499
1515
|
* @param {ForklaunchRouter<SV>[]} routers - The routers to include in the server.
|
1500
1516
|
* @returns {McpServer} - The generated ModelContextProtocol server.
|
1501
1517
|
*/
|
1502
|
-
declare function generateMcpServer(schemaValidator: ZodSchemaValidator, protocol: 'http' | 'https', host: string, port: number, version:
|
1518
|
+
declare function generateMcpServer<T extends Record<string, unknown> | undefined = Record<string, unknown> | undefined>(schemaValidator: ZodSchemaValidator, protocol: 'http' | 'https', host: string, port: number, version: `${number}.${number}.${number}`, routers: ForklaunchRouter<ZodSchemaValidator>[], options?: ConstructorParameters<typeof FastMCP<T>>[0], contentTypeMap?: Record<string, string>): FastMCP<T>;
|
1503
1519
|
|
1504
1520
|
/**
|
1505
1521
|
* Enhances the Express-like `send` method with additional logic for response handling and validation.
|
package/lib/http/index.d.ts
CHANGED
@@ -9,7 +9,7 @@ export { LevelWithSilent, LevelWithSilentOrString, Logger } from 'pino';
|
|
9
9
|
import { JWTPayload } from 'jose';
|
10
10
|
import { Readable } from 'stream';
|
11
11
|
import { ZodSchemaValidator } from '@forklaunch/validator/zod';
|
12
|
-
import {
|
12
|
+
import { FastMCP } from 'fastmcp';
|
13
13
|
import { OpenAPIObject } from 'openapi3-ts/oas31';
|
14
14
|
import { AnyValueMap } from '@opentelemetry/api-logs';
|
15
15
|
import { ApiReferenceConfiguration } from '@scalar/express-api-reference';
|
@@ -818,18 +818,18 @@ interface LiveTypeRouteDefinition<SV extends AnySchemaValidator, BasePath extend
|
|
818
818
|
sdk: object;
|
819
819
|
}> {
|
820
820
|
<Name extends string, Path extends `/${string}`, SuppliedPath extends Path, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>, Auth extends SchemaAuthMethods<SV, P, ReqBody, ReqQuery, ReqHeaders, BaseRequest>>(path: PathMatch<SuppliedPath, Path>, typedHandler: TypedHandler<SV, Name, ContractMethod, Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction, Auth>): ChainableRouter & {
|
821
|
-
fetchMap: Prettify<ChainableRouter['fetchMap'] & Record<SanitizePathSlashes<`${BasePath}${Path}`>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth
|
821
|
+
fetchMap: Prettify<ChainableRouter['fetchMap'] extends Record<SanitizePathSlashes<`${BasePath}${Path}`>, unknown> ? ChainableRouter['fetchMap'] & Record<SanitizePathSlashes<`${BasePath}${Path}`>, ChainableRouter['fetchMap'][SanitizePathSlashes<`${BasePath}${Path}`>] & Record<Uppercase<ContractMethod>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth>>> : ChainableRouter['fetchMap'] & Record<SanitizePathSlashes<`${BasePath}${Path}`>, Record<Uppercase<ContractMethod>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth>>>>;
|
822
822
|
sdk: Prettify<ChainableRouter['sdk'] & Record<PrettyCamelCase<Name>, LiveSdkFunction<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, Auth>>>;
|
823
823
|
};
|
824
824
|
<Name extends string, Path extends `/${string}`, SuppliedPath extends Path, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>, Auth extends SchemaAuthMethods<SV, P, ReqBody, ReqQuery, ReqHeaders, BaseRequest>>(path: PathMatch<SuppliedPath, Path>, middleware: ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction>, ...middlewareAndTypedHandler: [
|
825
825
|
...ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction>[],
|
826
826
|
TypedHandler<SV, Name, ContractMethod, Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction, Auth>
|
827
827
|
]): ChainableRouter & {
|
828
|
-
fetchMap: Prettify<ChainableRouter['fetchMap'] & Record<SanitizePathSlashes<`${BasePath}${Path}`>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth
|
828
|
+
fetchMap: Prettify<ChainableRouter['fetchMap'] extends Record<SanitizePathSlashes<`${BasePath}${Path}`>, unknown> ? ChainableRouter['fetchMap'] & Record<SanitizePathSlashes<`${BasePath}${Path}`>, ChainableRouter['fetchMap'][SanitizePathSlashes<`${BasePath}${Path}`>] & Record<Uppercase<ContractMethod>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth>>> : ChainableRouter['fetchMap'] & Record<SanitizePathSlashes<`${BasePath}${Path}`>, Record<Uppercase<ContractMethod>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth>>>>;
|
829
829
|
sdk: Prettify<ChainableRouter['sdk'] & Record<PrettyCamelCase<Name>, LiveSdkFunction<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, Auth>>>;
|
830
830
|
};
|
831
831
|
<Name extends string, Path extends `/${string}`, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>, Auth extends SchemaAuthMethods<SV, P, ReqBody, ReqQuery, ReqHeaders, BaseRequest>>(path: Path, contractDetails: ContractDetails<SV, Name, ContractMethod, Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, BaseRequest, Auth>, ...middleware: ExpressLikeSchemaHandler<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction>[]): ChainableRouter & {
|
832
|
-
fetchMap: Prettify<ChainableRouter['fetchMap'] & Record<SanitizePathSlashes<`${BasePath}${Path}`>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth
|
832
|
+
fetchMap: Prettify<ChainableRouter['fetchMap'] extends Record<SanitizePathSlashes<`${BasePath}${Path}`>, unknown> ? ChainableRouter['fetchMap'] & Record<SanitizePathSlashes<`${BasePath}${Path}`>, ChainableRouter['fetchMap'][SanitizePathSlashes<`${BasePath}${Path}`>] & Record<Uppercase<ContractMethod>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth>>> : ChainableRouter['fetchMap'] & Record<SanitizePathSlashes<`${BasePath}${Path}`>, Record<Uppercase<ContractMethod>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth>>>>;
|
833
833
|
sdk: Prettify<ChainableRouter['sdk'] & Record<PrettyCamelCase<Name>, LiveSdkFunction<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, Auth>>>;
|
834
834
|
};
|
835
835
|
}
|
@@ -982,7 +982,7 @@ type MiddlewareOrMiddlewareWithTypedHandler<SV extends AnySchemaValidator, Name
|
|
982
982
|
* });
|
983
983
|
* ```
|
984
984
|
**/
|
985
|
-
type FetchFunction<FetchMap> = <Path extends keyof FetchMap>(path: Path, ...reqInit: FetchMap[Path] extends TypeSafeFunction ? Parameters<FetchMap[Path]>[1] extends {
|
985
|
+
type FetchFunction<FetchMap> = <const Path extends keyof FetchMap, const Method extends keyof FetchMap[Path]>(path: Path, ...reqInit: FetchMap[Path][Method] extends TypeSafeFunction ? 'get' extends keyof FetchMap[Path] ? FetchMap[Path]['get'] extends TypeSafeFunction ? Parameters<FetchMap[Path]['get']>[1] extends {
|
986
986
|
body: unknown;
|
987
987
|
} | {
|
988
988
|
query: unknown;
|
@@ -990,7 +990,23 @@ type FetchFunction<FetchMap> = <Path extends keyof FetchMap>(path: Path, ...reqI
|
|
990
990
|
params: unknown;
|
991
991
|
} | {
|
992
992
|
headers: unknown;
|
993
|
-
} ? [
|
993
|
+
} ? [
|
994
|
+
reqInit: Omit<Parameters<FetchMap[Path][Method]>[1], 'method'> & {
|
995
|
+
method: Method;
|
996
|
+
}
|
997
|
+
] : [
|
998
|
+
reqInit?: Omit<Parameters<FetchMap[Path][Method]>[1], 'method'> & {
|
999
|
+
method: Method;
|
1000
|
+
}
|
1001
|
+
] : [
|
1002
|
+
reqInit: Omit<Parameters<FetchMap[Path][Method]>[1], 'method'> & {
|
1003
|
+
method: Method;
|
1004
|
+
}
|
1005
|
+
] : [
|
1006
|
+
reqInit: Omit<Parameters<FetchMap[Path][Method]>[1], 'method'> & {
|
1007
|
+
method: Method;
|
1008
|
+
}
|
1009
|
+
] : []) => Promise<FetchMap[Path][Method] extends TypeSafeFunction ? ReturnType<FetchMap[Path][Method]> : never>;
|
994
1010
|
/**
|
995
1011
|
* Creates a router SDK by combining the router's SDK with its fetch functionality.
|
996
1012
|
* This type merges the router's SDK interface with its fetch methods to create
|
@@ -1188,7 +1204,7 @@ declare class ForklaunchExpressLikeRouter<SV extends AnySchemaValidator, BasePat
|
|
1188
1204
|
*/
|
1189
1205
|
fetch: FetchFunction<this['fetchMap']>;
|
1190
1206
|
registerRoute<Name extends string, ContractMethod extends Method, Path extends `/${string}`, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>, const Auth extends SchemaAuthMethods<SV, P, ReqBody, ReqQuery, ReqHeaders, BaseRequest>>(method: ContractMethod, path: Path, registrationMethod: PathBasedHandler<RouterHandler>, contractDetailsOrMiddlewareOrTypedHandler: ContractDetailsOrMiddlewareOrTypedHandler<SV, Name, ContractMethod, Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction, Auth>, ...middlewareOrMiddlewareAndTypedHandler: MiddlewareOrMiddlewareWithTypedHandler<SV, Name, ContractMethod, Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction, Auth>[]): this & {
|
1191
|
-
fetchMap: Prettify<FetchMap & Record<SanitizePathSlashes<`${BasePath}${Path}`>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth
|
1207
|
+
fetchMap: Prettify<FetchMap extends Record<SanitizePathSlashes<`${BasePath}${Path}`>, unknown> ? FetchMap & Record<SanitizePathSlashes<`${BasePath}${Path}`>, FetchMap[SanitizePathSlashes<`${BasePath}${Path}`>] & Record<Uppercase<ContractMethod>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth>>> : FetchMap & Record<SanitizePathSlashes<`${BasePath}${Path}`>, Record<Uppercase<ContractMethod>, LiveTypeFunction<SV, SanitizePathSlashes<`${BasePath}${Path}`>, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, ContractMethod, Auth>>>>;
|
1192
1208
|
sdk: Prettify<Sdk & Record<PrettyCamelCase<Name extends string ? Name : SanitizePathSlashes<`${BasePath}${Path}`>>, LiveSdkFunction<SV, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, Auth>>>;
|
1193
1209
|
};
|
1194
1210
|
registerMiddlewareHandler<Name extends string, Path extends `/${string}`, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>, const Auth extends SchemaAuthMethods<SV, P, ReqBody, ReqQuery, ReqHeaders, BaseRequest>>(registrationMethod: PathOrMiddlewareBasedHandler<RouterHandler>, pathOrContractDetailsOrMiddlewareOrTypedHandler: Path | ContractDetailsOrMiddlewareOrTypedHandler<SV, Name, 'middleware', Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction, Auth> | RouterHandler, contractDetailsOrMiddlewareOrTypedHandler?: ContractDetailsOrMiddlewareOrTypedHandler<SV, Name, 'middleware', Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction, Auth> | RouterHandler, ...middlewareOrMiddlewareWithTypedHandler: (MiddlewareOrMiddlewareWithTypedHandler<SV, Name, 'middleware', Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction, Auth> | RouterHandler)[]): this;
|
@@ -1499,7 +1515,7 @@ declare const getCodeForStatus: (status: string) => null | StatusCode;
|
|
1499
1515
|
* @param {ForklaunchRouter<SV>[]} routers - The routers to include in the server.
|
1500
1516
|
* @returns {McpServer} - The generated ModelContextProtocol server.
|
1501
1517
|
*/
|
1502
|
-
declare function generateMcpServer(schemaValidator: ZodSchemaValidator, protocol: 'http' | 'https', host: string, port: number, version:
|
1518
|
+
declare function generateMcpServer<T extends Record<string, unknown> | undefined = Record<string, unknown> | undefined>(schemaValidator: ZodSchemaValidator, protocol: 'http' | 'https', host: string, port: number, version: `${number}.${number}.${number}`, routers: ForklaunchRouter<ZodSchemaValidator>[], options?: ConstructorParameters<typeof FastMCP<T>>[0], contentTypeMap?: Record<string, string>): FastMCP<T>;
|
1503
1519
|
|
1504
1520
|
/**
|
1505
1521
|
* Enhances the Express-like `send` method with additional logic for response handling and validation.
|
package/lib/http/index.js
CHANGED
@@ -2562,7 +2562,7 @@ var httpStatusCodes_default = HTTPStatuses;
|
|
2562
2562
|
// src/http/mcpGenerator/mcpGenerator.ts
|
2563
2563
|
var import_common8 = require("@forklaunch/common");
|
2564
2564
|
var import_zod = require("@forklaunch/validator/zod");
|
2565
|
-
var
|
2565
|
+
var import_fastmcp = require("fastmcp");
|
2566
2566
|
|
2567
2567
|
// src/http/router/unpackRouters.ts
|
2568
2568
|
var import_common7 = require("@forklaunch/common");
|
@@ -2591,14 +2591,15 @@ function unpackRouters(routers, recursiveBasePath = [], recursiveSdkPath = []) {
|
|
2591
2591
|
}
|
2592
2592
|
|
2593
2593
|
// src/http/mcpGenerator/mcpGenerator.ts
|
2594
|
-
function generateMcpServer(schemaValidator, protocol, host, port, version, routers, contentTypeMap) {
|
2594
|
+
function generateMcpServer(schemaValidator, protocol, host, port, version, routers, options2, contentTypeMap) {
|
2595
2595
|
if (!(schemaValidator instanceof import_zod.ZodSchemaValidator)) {
|
2596
2596
|
throw new Error(
|
2597
2597
|
"Schema validator must be an instance of ZodSchemaValidator"
|
2598
2598
|
);
|
2599
2599
|
}
|
2600
|
-
const mcpServer = new
|
2601
|
-
|
2600
|
+
const mcpServer = new import_fastmcp.FastMCP({
|
2601
|
+
...options2,
|
2602
|
+
name: options2?.name ?? "mcp-server",
|
2602
2603
|
version
|
2603
2604
|
});
|
2604
2605
|
unpackRouters(routers).forEach(({ fullPath, router }) => {
|
@@ -2610,7 +2611,7 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, route
|
|
2610
2611
|
route.contractDetails.body
|
2611
2612
|
);
|
2612
2613
|
}
|
2613
|
-
const inputSchema = {
|
2614
|
+
const inputSchema = schemaValidator.schemify({
|
2614
2615
|
...discriminatedBody && "body" in route.contractDetails ? {
|
2615
2616
|
..."contentType" in route.contractDetails.body ? { contentType: route.contractDetails.body.contentType } : {},
|
2616
2617
|
body: schemaValidator.schemify(discriminatedBody.schema)
|
@@ -2627,12 +2628,12 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, route
|
|
2627
2628
|
} : {}
|
2628
2629
|
})
|
2629
2630
|
} : {}
|
2630
|
-
};
|
2631
|
-
mcpServer.
|
2632
|
-
route.contractDetails.name,
|
2633
|
-
route.contractDetails.summary,
|
2634
|
-
inputSchema,
|
2635
|
-
async (args) => {
|
2631
|
+
});
|
2632
|
+
mcpServer.addTool({
|
2633
|
+
name: route.contractDetails.name,
|
2634
|
+
description: route.contractDetails.summary,
|
2635
|
+
parameters: inputSchema,
|
2636
|
+
execute: async (args) => {
|
2636
2637
|
const { contentType, body, params, query, headers } = args;
|
2637
2638
|
let url = `${protocol}://${host}:${port}${fullPath}${route.path}`;
|
2638
2639
|
if (params) {
|
@@ -2766,7 +2767,7 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, route
|
|
2766
2767
|
};
|
2767
2768
|
}
|
2768
2769
|
}
|
2769
|
-
);
|
2770
|
+
});
|
2770
2771
|
});
|
2771
2772
|
});
|
2772
2773
|
return mcpServer;
|