Skip to content

Commit cdbbf10

Browse files
committed
add missing file
Signed-off-by: Huamin Chen <[email protected]>
1 parent e428b7a commit cdbbf10

File tree

1 file changed

+99
-0
lines changed
  • src/semantic-router/pkg/connectivity/mcp/api

1 file changed

+99
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Package api defines the MCP protocol contract for semantic router classification.
2+
//
3+
// This package provides strongly-typed definitions for the JSON messages exchanged between
4+
// the Go client and MCP classification servers. These types ensure consistency and can be
5+
// used by both client and server implementations.
6+
//
7+
// Protocol Version: 1.0
8+
//
9+
// For Python MCP servers, use these JSON formats when implementing classification tools.
10+
// For other language implementations, these types can serve as reference for the expected format.
11+
package api
12+
13+
// ClassifyRequest represents the arguments for the classify_text tool call
14+
type ClassifyRequest struct {
15+
Text string `json:"text"` // Text to classify
16+
WithProbabilities bool `json:"with_probabilities,omitempty"` // Request full probability distribution
17+
}
18+
19+
// ClassifyResponse represents the response from the classify_text MCP tool.
20+
//
21+
// This is the core classification response format. The MCP server returns both classification
22+
// results (class index and confidence) and optional routing information (model and use_reasoning).
23+
//
24+
// Example JSON:
25+
// {
26+
// "class": 3,
27+
// "confidence": 0.85,
28+
// "model": "openai/gpt-oss-20b",
29+
// "use_reasoning": true
30+
// }
31+
type ClassifyResponse struct {
32+
// Class is the 0-based index of the predicted category
33+
Class int `json:"class"`
34+
35+
// Confidence is the prediction confidence, ranging from 0.0 to 1.0
36+
Confidence float32 `json:"confidence"`
37+
38+
// Model is the recommended model for routing this request (optional).
39+
// If provided, the router will use this model instead of the default_model.
40+
// Example: "openai/gpt-oss-20b", "anthropic/claude-3-opus"
41+
Model string `json:"model,omitempty"`
42+
43+
// UseReasoning indicates whether to enable reasoning mode for this request (optional).
44+
// If nil/omitted, the router uses its default reasoning configuration.
45+
// If true, enables reasoning mode. If false, disables reasoning mode.
46+
UseReasoning *bool `json:"use_reasoning,omitempty"`
47+
}
48+
49+
// ClassifyWithProbabilitiesResponse extends ClassifyResponse with full probability distribution.
50+
//
51+
// This format is used when the client requests detailed classification probabilities for all categories.
52+
// The MCP server should return this format when the classify_text tool is called with
53+
// "with_probabilities": true.
54+
//
55+
// Example JSON:
56+
// {
57+
// "class": 3,
58+
// "confidence": 0.85,
59+
// "probabilities": [0.05, 0.03, 0.07, 0.85, ...],
60+
// "model": "openai/gpt-oss-20b",
61+
// "use_reasoning": true
62+
// }
63+
type ClassifyWithProbabilitiesResponse struct {
64+
// Class is the 0-based index of the predicted category
65+
Class int `json:"class"`
66+
67+
// Confidence is the prediction confidence, ranging from 0.0 to 1.0
68+
Confidence float32 `json:"confidence"`
69+
70+
// Probabilities is the full probability distribution across all categories.
71+
// The array length must match the number of categories, and values should sum to ~1.0.
72+
Probabilities []float32 `json:"probabilities"`
73+
74+
// Model is the recommended model for routing this request (optional)
75+
Model string `json:"model,omitempty"`
76+
77+
// UseReasoning indicates whether to enable reasoning mode for this request (optional)
78+
UseReasoning *bool `json:"use_reasoning,omitempty"`
79+
}
80+
81+
// ListCategoriesResponse represents the response from the list_categories MCP tool.
82+
//
83+
// This format is used to retrieve the taxonomy of available categories from the MCP server.
84+
// The client calls this tool during initialization to discover which categories the server supports.
85+
//
86+
// Example JSON:
87+
// {
88+
// "categories": ["business", "law", "medical", "technical", "general"]
89+
// }
90+
type ListCategoriesResponse struct {
91+
// Categories is the ordered list of category names.
92+
// The index position in this array corresponds to the "class" index in ClassifyResponse.
93+
// For example, if Categories = ["business", "law", "medical"], then:
94+
// - class 0 = "business"
95+
// - class 1 = "law"
96+
// - class 2 = "medical"
97+
Categories []string `json:"categories"`
98+
}
99+

0 commit comments

Comments
 (0)