@agentica/core 0.19.1 → 0.21.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 +115 -413
  2. package/lib/MicroAgentica.js +4 -1
  3. package/lib/MicroAgentica.js.map +1 -1
  4. package/lib/context/AgenticaOperation.d.ts +3 -4
  5. package/lib/context/internal/AgenticaOperationComposer.js +1 -1
  6. package/lib/context/internal/AgenticaOperationComposer.js.map +1 -1
  7. package/lib/context/internal/AgenticaOperationComposer.spec.js +39 -10
  8. package/lib/context/internal/AgenticaOperationComposer.spec.js.map +1 -1
  9. package/lib/functional/assertHttpLlmApplication.js +168 -168
  10. package/lib/functional/assertMcpController.d.ts +24 -0
  11. package/lib/functional/assertMcpController.js +1699 -0
  12. package/lib/functional/assertMcpController.js.map +1 -0
  13. package/lib/functional/validateHttpLlmApplication.js +148 -148
  14. package/lib/index.d.ts +1 -1
  15. package/lib/index.js +1 -1
  16. package/lib/index.js.map +1 -1
  17. package/lib/index.mjs +1999 -406
  18. package/lib/index.mjs.map +1 -1
  19. package/lib/orchestrate/call.js +1 -1
  20. package/lib/orchestrate/call.js.map +1 -1
  21. package/lib/orchestrate/execute.js +13 -7
  22. package/lib/orchestrate/execute.js.map +1 -1
  23. package/lib/orchestrate/initialize.js +60 -60
  24. package/lib/structures/IAgenticaController.d.ts +8 -4
  25. package/lib/structures/IAgenticaExecutor.d.ts +10 -6
  26. package/lib/structures/IMicroAgenticaExecutor.d.ts +4 -1
  27. package/lib/structures/mcp/index.d.ts +0 -2
  28. package/lib/structures/mcp/index.js +0 -2
  29. package/lib/structures/mcp/index.js.map +1 -1
  30. package/package.json +3 -3
  31. package/src/MicroAgentica.ts +3 -1
  32. package/src/context/AgenticaOperation.ts +5 -6
  33. package/src/context/internal/AgenticaOperationComposer.spec.ts +45 -14
  34. package/src/context/internal/AgenticaOperationComposer.ts +9 -2
  35. package/src/functional/assertMcpController.ts +48 -0
  36. package/src/index.ts +1 -1
  37. package/src/orchestrate/call.ts +14 -4
  38. package/src/orchestrate/execute.ts +13 -7
  39. package/src/structures/IAgenticaController.ts +9 -4
  40. package/src/structures/IAgenticaExecutor.ts +16 -8
  41. package/src/structures/IMicroAgenticaExecutor.ts +10 -4
  42. package/src/structures/mcp/index.ts +0 -2
  43. package/lib/functional/assertMcpLlmApplication.d.ts +0 -18
  44. package/lib/functional/assertMcpLlmApplication.js +0 -74
  45. package/lib/functional/assertMcpLlmApplication.js.map +0 -1
  46. package/lib/structures/mcp/IMcpLlmApplication.d.ts +0 -9
  47. package/lib/structures/mcp/IMcpLlmApplication.js +0 -3
  48. package/lib/structures/mcp/IMcpLlmApplication.js.map +0 -1
  49. package/lib/structures/mcp/IMcpLlmFunction.d.ts +0 -17
  50. package/lib/structures/mcp/IMcpLlmFunction.js +0 -3
  51. package/lib/structures/mcp/IMcpLlmFunction.js.map +0 -1
  52. package/src/functional/assertMcpLlmApplication.ts +0 -32
  53. package/src/structures/mcp/IMcpLlmApplication.ts +0 -10
  54. package/src/structures/mcp/IMcpLlmFunction.ts +0 -19
@@ -85,9 +85,6 @@ const FUNCTION = {
85
85
  title: "Type schema info of the ChatGPT",
86
86
  description: "Type schema info of the ChatGPT.\n\n`IChatGptSchema` is a type schema info of the ChatGPT function calling.\n\n`IChatGptSchema` basically follows the JSON schema definition of the OpenAPI v3.1\nspeciifcation; {@link OpenApiV3_1.IJsonSchema}.\n\nHowever, the `IChatGptSchema` does not follow the entire specification of\nthe OpenAPI v3.1. It has own specific restrictions and definitions. Here is the\nlist of how `IChatGptSchema` is different with the OpenAPI v3.1 JSON schema.\n\n- Decompose mixed type: {@link OpenApiV3_1.IJsonSchema.IMixed}\n- Resolve nullable property: {@link OpenApiV3_1.IJsonSchema.__ISignificant.nullable}\n- Tuple type is banned: {@link OpenApiV3_1.IJsonSchema.ITuple.prefixItems}\n- Constant type is banned: {@link OpenApiV3_1.IJsonSchema.IConstant}\n- Merge {@link OpenApiV3_1.IJsonSchema.IOneOf} to {@link IChatGptSchema.IAnOf}\n- Merge {@link OpenApiV3_1.IJsonSchema.IAllOf} to {@link IChatGptSchema.IObject}\n- Merge {@link OpenApiV3_1.IJsonSchema.IRecursiveReference} to {@link IChatGptSchema.IReference}\n- When {@link IChatGptSchema.IConfig.strict} mode\n - Every object properties must be required\n - Do not allow {@link IChatGptSchema.IObject.additionalProperties}\n\nIf compare with the {@link OpenApi.IJsonSchema}, the emended JSON schema specification,\n\n- {@link IChatGptSchema.IAnyOf} instead of the {@link OpenApi.IJsonSchema.IOneOf}\n- {@link IChatGptSchema.IParameters.$defs} instead of the {@link OpenApi.IJsonSchema.IComponents.schemas}\n- {@link IChatGptSchema.IString.enum} instead of the {@link OpenApi.IJsonSchema.IConstant}\n- {@link IChatGptSchema.additionalProperties} is fixed to `false`\n- No tuple type {@link OpenApi.IJsonSchema.ITuple} support\n- When {@link IChatGptSchema.IConfig.strict} mode\n - Every object properties must be required\n - Do not allow {@link IChatGptSchema.IObject.additionalProperties}\n\nFor reference, if you've composed the `IChatGptSchema` type with the\n{@link IChatGptSchema.IConfig.reference} `false` option (default is `false`),\nonly the recursived named types would be archived into the\n{@link IChatGptSchema.IParameters.$defs}, and the others would be ecaped from the\n{@link IChatGptSchema.IReference} type.\n\nAlso, OpenAI has banned below constraint properties. Instead, `IChatGptSchema`\nfills the {@link IChatGptSchema.__IAttribute.description} property with\nthe comment text like `\"@format uuid\"`.\n\n- {@link OpenApi.IJsonSchema.INumber.minimum}\n- {@link OpenApi.IJsonSchema.INumber.maximum}\n- {@link OpenApi.IJsonSchema.INumber.multipleOf}\n- {@link OpenApi.IJsonSchema.IString.minLength}\n- {@link OpenApi.IJsonSchema.IString.maxLength}\n- {@link OpenApi.IJsonSchema.IString.format}\n- {@link OpenApi.IJsonSchema.IString.pattern}\n- {@link OpenApi.IJsonSchema.IString.contentMediaType}\n- {@link OpenApi.IJsonSchema.IString.default}\n- {@link OpenApi.IJsonSchema.IArray.minItems}\n- {@link OpenApi.IJsonSchema.IArray.maxItems}\n- {@link OpenApi.IJsonSchema.IArray.unique}\n\nAdditionally, OpenAI cannot define the `description` property to the\n{@link IChatGptSchema.IReference} type, and even does not understand\nthe capsulization to the {@link IChatGptSchema.IAnyOf} type.\nTherefore, the `description` is written to the parent object type,\nnot the reference type.\n\n```json\n{\n \"type\": \"object\",\n \"description\": \"### Description of {@link something} property.\\n\\n> Hello?\",\n \"properties\": {\n \"something\": {\n \"$ref\": \"#/$defs/SomeObject\"\n }\n }\n}\n```",
87
87
  anyOf: [
88
- {
89
- $ref: "#/$defs/IChatGptSchema.IObject"
90
- },
91
88
  {
92
89
  type: "object",
93
90
  properties: {
@@ -295,6 +292,9 @@ const FUNCTION = {
295
292
  {
296
293
  $ref: "#/$defs/IChatGptSchema.IArray"
297
294
  },
295
+ {
296
+ $ref: "#/$defs/IChatGptSchema.IObject"
297
+ },
298
298
  {
299
299
  type: "object",
300
300
  properties: {
@@ -416,6 +416,54 @@ const FUNCTION = {
416
416
  }
417
417
  ]
418
418
  },
419
+ "IChatGptSchema.IArray": {
420
+ description: "Array type info.\n\n### Description of {@link items} property:\n\n> Items type info.\n> \n> The `items` means the type of the array elements. In other words, it is\n> the type schema info of the `T` in the TypeScript array type `Array<T>`.",
421
+ type: "object",
422
+ properties: {
423
+ items: {
424
+ title: "Items type info",
425
+ $ref: "#/$defs/IChatGptSchema"
426
+ },
427
+ type: {
428
+ title: "Discriminator value of the type",
429
+ description: "Discriminator value of the type.",
430
+ type: "string",
431
+ "enum": [
432
+ "array"
433
+ ]
434
+ },
435
+ title: {
436
+ title: "Title of the schema",
437
+ description: "Title of the schema.",
438
+ type: "string"
439
+ },
440
+ description: {
441
+ title: "Detailed description of the schema",
442
+ description: "Detailed description of the schema.",
443
+ type: "string"
444
+ },
445
+ deprecated: {
446
+ title: "Whether the type is deprecated or not",
447
+ description: "Whether the type is deprecated or not.",
448
+ type: "boolean"
449
+ },
450
+ example: {
451
+ title: "Example value",
452
+ description: "Example value."
453
+ },
454
+ examples: {
455
+ description: "List of example values as key-value pairs.\n\n------------------------------\n\nDescription of the current {@link Recordstringany} type:\n\n> Construct a type with a set of properties K of type T",
456
+ type: "object",
457
+ properties: {},
458
+ required: [],
459
+ additionalProperties: {}
460
+ }
461
+ },
462
+ required: [
463
+ "items",
464
+ "type"
465
+ ]
466
+ },
419
467
  "IChatGptSchema.IObject": {
420
468
  description: "Object type info.\n\n### Description of {@link properties} property:\n\n> Properties of the object.\n> \n> The `properties` means a list of key-value pairs of the object's\n> regular properties. The key is the name of the regular property,\n> and the value is the type schema info.",
421
469
  type: "object",
@@ -431,9 +479,6 @@ const FUNCTION = {
431
479
  {
432
480
  type: "boolean"
433
481
  },
434
- {
435
- $ref: "#/$defs/IChatGptSchema.IObject"
436
- },
437
482
  {
438
483
  type: "object",
439
484
  properties: {
@@ -641,6 +686,9 @@ const FUNCTION = {
641
686
  {
642
687
  $ref: "#/$defs/IChatGptSchema.IArray"
643
688
  },
689
+ {
690
+ $ref: "#/$defs/IChatGptSchema.IObject"
691
+ },
644
692
  {
645
693
  type: "object",
646
694
  properties: {
@@ -811,54 +859,6 @@ const FUNCTION = {
811
859
  "type"
812
860
  ]
813
861
  },
814
- "IChatGptSchema.IArray": {
815
- description: "Array type info.\n\n### Description of {@link items} property:\n\n> Items type info.\n> \n> The `items` means the type of the array elements. In other words, it is\n> the type schema info of the `T` in the TypeScript array type `Array<T>`.",
816
- type: "object",
817
- properties: {
818
- items: {
819
- title: "Items type info",
820
- $ref: "#/$defs/IChatGptSchema"
821
- },
822
- type: {
823
- title: "Discriminator value of the type",
824
- description: "Discriminator value of the type.",
825
- type: "string",
826
- "enum": [
827
- "array"
828
- ]
829
- },
830
- title: {
831
- title: "Title of the schema",
832
- description: "Title of the schema.",
833
- type: "string"
834
- },
835
- description: {
836
- title: "Detailed description of the schema",
837
- description: "Detailed description of the schema.",
838
- type: "string"
839
- },
840
- deprecated: {
841
- title: "Whether the type is deprecated or not",
842
- description: "Whether the type is deprecated or not.",
843
- type: "boolean"
844
- },
845
- example: {
846
- title: "Example value",
847
- description: "Example value."
848
- },
849
- examples: {
850
- description: "List of example values as key-value pairs.\n\n------------------------------\n\nDescription of the current {@link Recordstringany} type:\n\n> Construct a type with a set of properties K of type T",
851
- type: "object",
852
- properties: {},
853
- required: [],
854
- additionalProperties: {}
855
- }
856
- },
857
- required: [
858
- "items",
859
- "type"
860
- ]
861
- },
862
862
  "IChatGptSchema.IAnyOf": {
863
863
  description: "Union type.\n\nIOneOf` represents an union type of the TypeScript (`A | B | C`).\n\nFor reference, even though your Swagger (or OpenAPI) document has\ndefined `anyOf` instead of the `oneOf`, {@link IChatGptSchema} forcibly\nconverts it to `oneOf` type.",
864
864
  type: "object",
@@ -869,9 +869,6 @@ const FUNCTION = {
869
869
  type: "array",
870
870
  items: {
871
871
  anyOf: [
872
- {
873
- $ref: "#/$defs/IChatGptSchema.IObject"
874
- },
875
872
  {
876
873
  type: "object",
877
874
  properties: {
@@ -1079,6 +1076,9 @@ const FUNCTION = {
1079
1076
  {
1080
1077
  $ref: "#/$defs/IChatGptSchema.IArray"
1081
1078
  },
1079
+ {
1080
+ $ref: "#/$defs/IChatGptSchema.IObject"
1081
+ },
1082
1082
  {
1083
1083
  type: "object",
1084
1084
  properties: {
@@ -1495,9 +1495,6 @@ const FUNCTION = {
1495
1495
  title: "Expected return type",
1496
1496
  description: "Expected return type.\n\nIf the target operation returns nothing (`void`), the `output`\nwould be `undefined`.",
1497
1497
  anyOf: [
1498
- {
1499
- $ref: "#/$defs/IChatGptSchema.IObject"
1500
- },
1501
1498
  {
1502
1499
  type: "object",
1503
1500
  properties: {
@@ -1705,6 +1702,9 @@ const FUNCTION = {
1705
1702
  {
1706
1703
  $ref: "#/$defs/IChatGptSchema.IArray"
1707
1704
  },
1705
+ {
1706
+ $ref: "#/$defs/IChatGptSchema.IObject"
1707
+ },
1708
1708
  {
1709
1709
  type: "object",
1710
1710
  properties: {
@@ -1,5 +1,5 @@
1
- import type { IHttpConnection, IHttpLlmApplication, IHttpLlmFunction, IHttpResponse, ILlmApplication, ILlmFunction, ILlmSchema } from "@samchon/openapi";
2
- import type { IMcpLlmApplication } from "./mcp/IMcpLlmApplication";
1
+ import type { Client } from "@modelcontextprotocol/sdk/client/index.d.ts";
2
+ import type { IHttpConnection, IHttpLlmApplication, IHttpLlmFunction, IHttpResponse, ILlmApplication, ILlmFunction, ILlmSchema, IMcpLlmApplication } from "@samchon/openapi";
3
3
  /**
4
4
  * Controller of the Agentica Agent.
5
5
  *
@@ -16,7 +16,7 @@ import type { IMcpLlmApplication } from "./mcp/IMcpLlmApplication";
16
16
  *
17
17
  * @author Samchon
18
18
  */
19
- export type IAgenticaController<Model extends ILlmSchema.Model> = IAgenticaController.IHttp<Model> | IAgenticaController.IClass<Model> | IAgenticaController.IMcp;
19
+ export type IAgenticaController<Model extends ILlmSchema.Model> = IAgenticaController.IHttp<Model> | IAgenticaController.IClass<Model> | IAgenticaController.IMcp<Model>;
20
20
  export declare namespace IAgenticaController {
21
21
  /**
22
22
  * HTTP controller.
@@ -96,7 +96,11 @@ export declare namespace IAgenticaController {
96
96
  /**
97
97
  * MCP Server controller.
98
98
  */
99
- export interface IMcp extends IBase<"mcp", IMcpLlmApplication> {
99
+ export interface IMcp<Model extends ILlmSchema.Model> extends IBase<"mcp", IMcpLlmApplication<Model>> {
100
+ /**
101
+ * MCP client for connection.
102
+ */
103
+ client: Client;
100
104
  }
101
105
  interface IBase<Protocol, Application> {
102
106
  /**
@@ -47,15 +47,16 @@ export interface IAgenticaExecutor<Model extends ILlmSchema.Model> {
47
47
  * conversate with the user.
48
48
  *
49
49
  * By the way, if you wanna skip the `initialize` agent, you can
50
- * do it by configuring the {@link IAgenticaConfig.executor} as
51
- * `null` value. In that case, the `initialize` agent will never be
52
- * called, and {@link Agentica} just starts from the {@link select}
53
- * agent.
50
+ * do it by configuring the {@link IAgenticaExecutor.initialize} as
51
+ * `undefined`, `false` or `null` value. In that case, the `initialize`
52
+ * agent will never be called, and {@link Agentica} just starts from the
53
+ * {@link select} agent.
54
54
  *
55
55
  * @param ctx Context of the agent
56
56
  * @returns List of prompts generated by the initializer
57
+ * @default false
57
58
  */
58
- initialize: null | ((ctx: AgenticaContext<Model>) => Promise<AgenticaHistory<Model>[]>);
59
+ initialize: boolean | null | ((ctx: AgenticaContext<Model>) => Promise<AgenticaHistory<Model>[]>);
59
60
  /**
60
61
  * Function selector agent.
61
62
  *
@@ -117,11 +118,14 @@ export interface IAgenticaExecutor<Model extends ILlmSchema.Model> {
117
118
  * `Describe` agent explains the results of the function callings
118
119
  * to the user as markdown content.
119
120
  *
121
+ * If you configure this property as `false` or `null`, the describer
122
+ * agent will never be used.
123
+ *
120
124
  * @param ctx Context of the agent
121
125
  * @param executes List of function calling results
122
126
  * @returns List of prompts generated by the describer
123
127
  */
124
- describe: (ctx: AgenticaContext<Model>, executes: AgenticaExecuteHistory<Model>[]) => Promise<AgenticaHistory<Model>[]>;
128
+ describe: boolean | null | ((ctx: AgenticaContext<Model>, executes: AgenticaExecuteHistory<Model>[]) => Promise<AgenticaHistory<Model>[]>);
125
129
  /**
126
130
  * Function canceler agent.
127
131
  *
@@ -49,9 +49,12 @@ export interface IMicroAgenticaExecutor<Model extends ILlmSchema.Model> {
49
49
  * `Describe` agent explains the results of the function callings
50
50
  * to the user as markdown content.
51
51
  *
52
+ * If you configure this property as `false` or `null`, the describer
53
+ * agent never be used.
54
+ *
52
55
  * @param ctx Context of the agent
53
56
  * @param executes List of function calling results
54
57
  * @returns List of prompts generated by the describer
55
58
  */
56
- describe: (ctx: MicroAgenticaContext<Model>, executes: AgenticaExecuteHistory<Model>[]) => Promise<MicroAgenticaHistory<Model>[]>;
59
+ describe: boolean | null | ((ctx: MicroAgenticaContext<Model>, executes: AgenticaExecuteHistory<Model>[]) => Promise<MicroAgenticaHistory<Model>[]>);
57
60
  }
@@ -1,3 +1 @@
1
- export * from "./IMcpLlmApplication";
2
- export * from "./IMcpLlmFunction";
3
1
  export * from "./IMcpLlmTransportProps";
@@ -14,7 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./IMcpLlmApplication"), exports);
18
- __exportStar(require("./IMcpLlmFunction"), exports);
19
17
  __exportStar(require("./IMcpLlmTransportProps"), exports);
20
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/structures/mcp/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,oDAAkC;AAClC,0DAAwC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/structures/mcp/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentica/core",
3
- "version": "0.19.1",
3
+ "version": "0.21.0",
4
4
  "description": "Agentic AI Library specialized in LLM Function Calling",
5
5
  "author": "Wrtn Technologies",
6
6
  "license": "MIT",
@@ -37,12 +37,12 @@
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@modelcontextprotocol/sdk": "^1.9.0",
40
- "@samchon/openapi": "^4.0.0",
40
+ "@samchon/openapi": "^4.2.0",
41
41
  "openai": "^4.80.0",
42
42
  "typia": "^9.0.1"
43
43
  },
44
44
  "dependencies": {
45
- "@samchon/openapi": "^4.0.0",
45
+ "@samchon/openapi": "^4.2.0",
46
46
  "typia": "^9.0.1",
47
47
  "uuid": "^11.0.4"
48
48
  },
@@ -131,7 +131,9 @@ export class MicroAgentica<Model extends ILlmSchema.Model> {
131
131
  this.operations_.array,
132
132
  ) as MicroAgenticaHistory<Model>[];
133
133
  const executes: AgenticaExecuteHistory<Model>[] = histories.filter(p => p.type === "execute");
134
- if (executes.length) {
134
+ if (executes.length
135
+ && ctx.config?.executor?.describe !== null
136
+ && ctx.config?.executor?.describe !== false) {
135
137
  histories.push(...await describe(ctx, executes));
136
138
  }
137
139
 
@@ -1,8 +1,7 @@
1
- import type { IHttpLlmFunction, ILlmFunction, ILlmSchema } from "@samchon/openapi";
1
+ import type { IHttpLlmFunction, ILlmFunction, ILlmSchema, IMcpLlmFunction } from "@samchon/openapi";
2
2
 
3
3
  import type { IAgenticaOperationJson } from "../json/IAgenticaOperationJson";
4
4
  import type { IAgenticaController } from "../structures/IAgenticaController";
5
- import type { IMcpLlmFunction } from "../structures/mcp/IMcpLlmFunction";
6
5
 
7
6
  /**
8
7
  * Operation information in the Agentica Agent.
@@ -22,7 +21,7 @@ import type { IMcpLlmFunction } from "../structures/mcp/IMcpLlmFunction";
22
21
  export type AgenticaOperation<Model extends ILlmSchema.Model> =
23
22
  | AgenticaOperation.Class<Model>
24
23
  | AgenticaOperation.Http<Model>
25
- | AgenticaOperation.Mcp;
24
+ | AgenticaOperation.Mcp<Model>;
26
25
  export namespace AgenticaOperation {
27
26
  export type Class<Model extends ILlmSchema.Model> = Base<
28
27
  "class",
@@ -34,10 +33,10 @@ export namespace AgenticaOperation {
34
33
  IAgenticaController.IHttp<Model>,
35
34
  IHttpLlmFunction<Model>
36
35
  >;
37
- export type Mcp = Base<
36
+ export type Mcp<Model extends ILlmSchema.Model> = Base<
38
37
  "mcp",
39
- IAgenticaController.IMcp,
40
- IMcpLlmFunction
38
+ IAgenticaController.IMcp<Model>,
39
+ IMcpLlmFunction<Model>
41
40
  >;
42
41
 
43
42
  interface Base<
@@ -1,13 +1,12 @@
1
- import type { IHttpLlmFunction, ILlmFunction, IValidation } from "@samchon/openapi";
1
+ import type { IChatGptSchema, IHttpLlmFunction, ILlmFunction, IMcpLlmFunction, IValidation } from "@samchon/openapi";
2
2
 
3
3
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
4
4
  import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
5
5
 
6
6
  import type { IAgenticaConfig } from "../../structures/IAgenticaConfig";
7
7
  import type { IAgenticaController } from "../../structures/IAgenticaController";
8
- import type { IMcpLlmFunction } from "../../structures/mcp/IMcpLlmFunction";
9
8
 
10
- import { assertMcpLlmApplication } from "../../functional/assertMcpLlmApplication";
9
+ import { assertMcpController } from "../../functional/assertMcpController";
11
10
 
12
11
  import { compose, divide, getOperations, toClassOperations, toHttpOperations, toMcpOperations } from "./AgenticaOperationComposer";
13
12
 
@@ -70,16 +69,18 @@ function createMockClassController(name: string, functions: ILlmFunction<any>[])
70
69
  };
71
70
  }
72
71
 
73
- async function createMockMcpController(name: string, functions: IMcpLlmFunction[]): Promise<IAgenticaController.IMcp> {
74
- return {
72
+ async function createMockMcpController(name: string, functions: IMcpLlmFunction<"chatgpt">[]): Promise<IAgenticaController.IMcp<"chatgpt">> {
73
+ const controller = await assertMcpController({
74
+ model: "chatgpt",
75
75
  name,
76
- protocol: "mcp",
77
- application: await assertMcpLlmApplication({
78
- client,
79
- }).then(v => ({
80
- ...v,
76
+ client,
77
+ });
78
+ return {
79
+ ...controller,
80
+ application: {
81
+ ...controller.application,
81
82
  functions,
82
- })),
83
+ },
83
84
  };
84
85
  }
85
86
 
@@ -110,7 +111,17 @@ describe("a AgenticaOperationComposer", () => {
110
111
  const mockMcpController = await createMockMcpController("mcpController", [
111
112
  {
112
113
  name: "function4",
113
- parameters: {},
114
+ parameters: {
115
+ type: "object",
116
+ properties: {},
117
+ additionalProperties: false,
118
+ required: [],
119
+ $defs: {},
120
+ } satisfies IChatGptSchema.IParameters,
121
+ validate: (data: unknown) => ({
122
+ success: true,
123
+ data,
124
+ }),
114
125
  },
115
126
  ]);
116
127
 
@@ -182,7 +193,17 @@ describe("a AgenticaOperationComposer", () => {
182
193
  const mockController = await createMockMcpController("mcpController", [
183
194
  {
184
195
  name: "function1",
185
- parameters: {},
196
+ parameters: {
197
+ type: "object",
198
+ properties: {},
199
+ additionalProperties: false,
200
+ required: [],
201
+ $defs: {},
202
+ },
203
+ validate: (data: unknown) => ({
204
+ success: true,
205
+ data,
206
+ }),
186
207
  },
187
208
  ]);
188
209
 
@@ -245,7 +266,17 @@ describe("a AgenticaOperationComposer", () => {
245
266
  const mockController = await createMockMcpController("mcpController", [
246
267
  {
247
268
  name: "function1",
248
- parameters: {},
269
+ parameters: {
270
+ type: "object",
271
+ properties: {},
272
+ additionalProperties: false,
273
+ required: [],
274
+ $defs: {},
275
+ },
276
+ validate: (data: unknown) => ({
277
+ success: true,
278
+ data,
279
+ }),
249
280
  },
250
281
  ]);
251
282
 
@@ -21,7 +21,10 @@ export function compose<Model extends ILlmSchema.Model>(props: {
21
21
  config?: IAgenticaConfig<Model> | IMicroAgenticaConfig<Model> | undefined;
22
22
  }): AgenticaOperationCollection<Model> {
23
23
  const unique: boolean = (props.controllers.length === 1 || (() => {
24
- const names = props.controllers.map(controllers => controllers.application.functions.map(func => func.name)).flat();
24
+ const names = props.controllers.map(
25
+
26
+ controllers => controllers.application.functions.map((func: { name: string }) => func.name),
27
+ ).flat();
25
28
  return new Set(names).size === names.length;
26
29
  })());
27
30
 
@@ -126,19 +129,23 @@ export function toClassOperations<Model extends ILlmSchema.Model>(props: {
126
129
  * @internal
127
130
  */
128
131
  export function toMcpOperations<Model extends ILlmSchema.Model>(props: {
129
- controller: IAgenticaController.IMcp;
132
+ controller: IAgenticaController.IMcp<Model>;
130
133
  index: number;
131
134
  naming: (func: string, controllerIndex: number) => string;
132
135
  }): AgenticaOperation<Model>[] {
133
136
  return props.controller.application.functions.map(func => ({
134
137
  protocol: "mcp",
135
138
  controller: props.controller,
139
+
136
140
  function: func,
141
+
137
142
  name: props.naming(func.name, props.index),
138
143
  toJSON: () => ({
139
144
  protocol: "mcp",
140
145
  controller: props.controller.name,
146
+
141
147
  function: func.name,
148
+
142
149
  name: props.naming(func.name, props.index),
143
150
  }),
144
151
  }));
@@ -0,0 +1,48 @@
1
+ import type { Client } from "@modelcontextprotocol/sdk/client/index.d.ts";
2
+ import type { ILlmSchema, IMcpLlmApplication, IMcpTool } from "@samchon/openapi";
3
+
4
+ import { McpLlm } from "@samchon/openapi";
5
+ import typia from "typia";
6
+
7
+ import type { IAgenticaController } from "../structures/IAgenticaController";
8
+
9
+ /**
10
+ * Create an MCP controller with type assertion.
11
+ *
12
+ * Create an {@link IAgenticaController.IMcp} instance which represents
13
+ * an MCP (Model Context Protocol) controller with LLM function calling
14
+ * schemas and client connection.
15
+ *
16
+ * @param props Properties to create the MCP controller
17
+ * @param props.name Name of the MCP implementation.
18
+ * @param props.client Client connection to the MCP implementation.
19
+ * @param props.model Model schema of the LLM function calling.
20
+ * @param props.options Options to create the MCP controller.
21
+ * @returns MCP LLM application instance
22
+ * @author Samchon
23
+ */
24
+ export async function assertMcpController<Model extends ILlmSchema.Model>(props: {
25
+ name: string;
26
+ client: Client;
27
+ model: Model;
28
+ options?: Partial<IMcpLlmApplication.IOptions<Model>>;
29
+ }): Promise<IAgenticaController.IMcp<Model>> {
30
+ // for peerDependencies
31
+ const { ListToolsResultSchema } = await import("@modelcontextprotocol/sdk/types.js");
32
+
33
+ // get list of tools
34
+ const { tools } = await props.client.request({ method: "tools/list" }, ListToolsResultSchema);
35
+
36
+ const application: IMcpLlmApplication<Model> = McpLlm.application<Model>({
37
+ model: props.model,
38
+ tools: typia.assert<Array<IMcpTool>>(tools),
39
+ });
40
+
41
+ return {
42
+ protocol: "mcp",
43
+ name: props.name,
44
+ client: props.client,
45
+
46
+ application,
47
+ };
48
+ }
package/src/index.ts CHANGED
@@ -23,7 +23,7 @@ export * from "./events/MicroAgenticaEvent";
23
23
  export * as factory from "./factory";
24
24
 
25
25
  export * from "./functional/assertHttpLlmApplication";
26
- export * from "./functional/assertMcpLlmApplication";
26
+ export * from "./functional/assertMcpController";
27
27
  export * from "./functional/validateHttpLlmApplication";
28
28
  // @TODO: implement validateMcpLlmApplication
29
29
 
@@ -72,10 +72,13 @@ export async function call<Model extends ILlmSchema.Model>(
72
72
  type: "function",
73
73
  function: {
74
74
  name: s.name,
75
+
75
76
  description: s.function.description,
76
77
  parameters: (
77
78
  "separated" in s.function
79
+
78
80
  && s.function.separated !== undefined
81
+
79
82
  ? (s.function.separated.llm
80
83
  ?? ({
81
84
  type: "object",
@@ -84,6 +87,7 @@ export async function call<Model extends ILlmSchema.Model>(
84
87
  additionalProperties: false,
85
88
  $defs: {},
86
89
  } satisfies IChatGptSchema.IParameters))
90
+
87
91
  : s.function.parameters) as Record<string, any>,
88
92
  },
89
93
  }) as OpenAI.ChatCompletionTool,
@@ -368,7 +372,7 @@ async function propagateClass<Model extends ILlmSchema.Model>(props: {
368
372
 
369
373
  async function propagateMcp<Model extends ILlmSchema.Model>(props: {
370
374
  ctx: AgenticaContext<Model> | MicroAgenticaContext<Model>;
371
- operation: AgenticaOperation.Mcp;
375
+ operation: AgenticaOperation.Mcp<Model>;
372
376
  call: AgenticaCallEvent<Model>;
373
377
  retry: number;
374
378
  }): Promise<AgenticaExecuteHistory<Model>> {
@@ -435,12 +439,14 @@ async function executeClassOperation<Model extends ILlmSchema.Model>(operation:
435
439
  return ((execute as Record<string, unknown>)[operation.function.name] as (...args: unknown[]) => Promise<unknown>)(operationArguments);
436
440
  }
437
441
 
438
- async function executeMcpOperation(
439
- operation: AgenticaOperation.Mcp,
442
+ async function executeMcpOperation<Model extends ILlmSchema.Model>(
443
+ operation: AgenticaOperation.Mcp<Model>,
440
444
  operationArguments: Record<string, unknown>,
441
445
  ): Promise<unknown> {
442
- return operation.controller.application.client.callTool({
446
+ return operation.controller.client.callTool({
447
+
443
448
  method: operation.function.name,
449
+
444
450
  name: operation.function.name,
445
451
  arguments: operationArguments,
446
452
  }).then(v => v.content);
@@ -512,6 +518,7 @@ async function correct<Model extends ILlmSchema.Model>(
512
518
  type: "function",
513
519
  function: {
514
520
  name: call.operation.name,
521
+
515
522
  description: call.operation.function.description,
516
523
  /**
517
524
  * @TODO fix it
@@ -519,7 +526,9 @@ async function correct<Model extends ILlmSchema.Model>(
519
526
  */
520
527
  parameters: (
521
528
  "separated" in call.operation.function
529
+
522
530
  && call.operation.function.separated !== undefined
531
+
523
532
  ? (call.operation.function.separated?.llm
524
533
  ?? ({
525
534
  $defs: {},
@@ -528,6 +537,7 @@ async function correct<Model extends ILlmSchema.Model>(
528
537
  additionalProperties: false,
529
538
  required: [],
530
539
  } satisfies IChatGptSchema.IParameters))
540
+
531
541
  : call.operation.function.parameters) as unknown as Record<string, unknown>,
532
542
  },
533
543
  },