Skip to content

Commit 06b56c9

Browse files
Merge pull request #2 from Vishnu-Opsera/feat/mcp-server-updated/2025-08-21--11-04-11
2 parents 6282801 + 2354f5a commit 06b56c9

8 files changed

Lines changed: 461 additions & 1 deletion

File tree

MCP/models/models.go

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,71 @@ type Tool struct {
1212

1313
// Error represents the Error schema from the OpenAPI specification
1414
type Error struct {
15-
Code int `json:"code,omitempty"`
1615
Message string `json:"message,omitempty"`
16+
Code int `json:"code,omitempty"`
17+
}
18+
19+
// ErrorResponse represents the ErrorResponse schema from the OpenAPI specification
20+
type ErrorResponse struct {
21+
Timestamp string `json:"timestamp,omitempty"` // Error timestamp
22+
ErrorField string `json:"error,omitempty"` // Technical error details
23+
Message string `json:"message,omitempty"` // Error message
24+
}
25+
26+
// APIResponse represents the APIResponse schema from the OpenAPI specification
27+
type APIResponse struct {
28+
Data map[string]interface{} `json:"data,omitempty"` // Response data
29+
Message string `json:"message,omitempty"` // Response message
30+
Success bool `json:"success,omitempty"` // Operation success status
31+
}
32+
33+
// CustomerResponse represents the CustomerResponse schema from the OpenAPI specification
34+
type CustomerResponse struct {
35+
Message string `json:"message,omitempty"` // Response message
36+
Success bool `json:"success,omitempty"` // Operation success status
37+
Customer Customer `json:"customer,omitempty"`
38+
}
39+
40+
// Success represents the Success schema from the OpenAPI specification
41+
type Success struct {
42+
Data map[string]interface{} `json:"data,omitempty"` // Response data
43+
Message string `json:"message,omitempty"` // Success message
44+
Success bool `json:"success,omitempty"` // Operation success status
45+
}
46+
47+
// Broker represents the Broker schema from the OpenAPI specification
48+
type Broker struct {
49+
Name string `json:"name,omitempty"` // Broker name
50+
Status string `json:"status,omitempty"` // Broker status
51+
Endpoint string `json:"endpoint,omitempty"` // Broker endpoint URL
52+
Id string `json:"id,omitempty"` // Broker unique identifier
53+
}
54+
55+
// Artifact represents the Artifact schema from the OpenAPI specification
56+
type Artifact struct {
57+
Customerid string `json:"customerId,omitempty"` // Customer ID associated with the artifact
58+
Id string `json:"id,omitempty"` // Artifact unique identifier
59+
Name string `json:"name,omitempty"` // Artifact name
60+
Size int `json:"size,omitempty"` // Artifact size in bytes
61+
TypeField string `json:"type,omitempty"` // Artifact type
62+
Updatedat string `json:"updatedAt,omitempty"` // Last update timestamp
63+
Createdat string `json:"createdAt,omitempty"` // Creation timestamp
64+
}
65+
66+
// Customer represents the Customer schema from the OpenAPI specification
67+
type Customer struct {
68+
Createdat string `json:"createdAt,omitempty"` // Creation timestamp
69+
Email string `json:"email,omitempty"` // Customer email address
70+
Id string `json:"id,omitempty"` // Customer unique identifier
71+
Name string `json:"name,omitempty"` // Customer name
72+
}
73+
74+
// BrokerInfo represents the BrokerInfo schema from the OpenAPI specification
75+
type BrokerInfo struct {
76+
Id string `json:"id,omitempty"` // Broker unique identifier
77+
Lasthealthcheck string `json:"lastHealthCheck,omitempty"` // Last health check timestamp
78+
Name string `json:"name,omitempty"` // Broker name
79+
Status string `json:"status,omitempty"` // Broker status
80+
TypeField string `json:"type,omitempty"` // Broker type
81+
Endpoint string `json:"endpoint,omitempty"` // Broker endpoint URL
1782
}

MCP/registry.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,24 @@ package main
33
import (
44
"github.com/input-api/mcp-server/config"
55
"github.com/input-api/mcp-server/models"
6+
tools_auth "github.com/input-api/mcp-server/tools/auth"
7+
tools_api "github.com/input-api/mcp-server/tools/api"
8+
tools_mcp "github.com/input-api/mcp-server/tools/mcp"
69
tools_openapi "github.com/input-api/mcp-server/tools/openapi"
710
tools_openapi_type_json_yaml "github.com/input-api/mcp-server/tools/openapi_type_json_yaml"
11+
tools_config "github.com/input-api/mcp-server/tools/config"
12+
tools_authentication "github.com/input-api/mcp-server/tools/authentication"
813
)
914

1015
func GetAll(cfg *config.APIConfig) []models.Tool {
1116
return []models.Tool{
17+
tools_auth.CreateHead_basic_authTool(cfg),
18+
tools_auth.CreateHead_bearer_tokenTool(cfg),
19+
tools_api.CreateGetTool(cfg),
20+
tools_mcp.CreateGet_mcpTool(cfg),
1221
tools_openapi.CreateGet_openapiTool(cfg),
1322
tools_openapi_type_json_yaml.CreateGet_openapi_typejsonyamlTool(cfg),
23+
tools_config.CreateHead_api_base_urlTool(cfg),
24+
tools_authentication.CreateHead_api_keyTool(cfg),
1425
}
1526
}

MCP/tools/api/get.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package tools
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"io"
8+
"net/http"
9+
10+
"github.com/input-api/mcp-server/config"
11+
"github.com/input-api/mcp-server/models"
12+
"github.com/mark3labs/mcp-go/mcp"
13+
)
14+
15+
func GetHandler(cfg *config.APIConfig) func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
16+
return func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
17+
url := fmt.Sprintf("%s/", cfg.BaseURL)
18+
req, err := http.NewRequest("GET", url, nil)
19+
if err != nil {
20+
return mcp.NewToolResultErrorFromErr("Failed to create request", err), nil
21+
}
22+
// No authentication required for this endpoint
23+
req.Header.Set("Accept", "application/json")
24+
25+
resp, err := http.DefaultClient.Do(req)
26+
if err != nil {
27+
return mcp.NewToolResultErrorFromErr("Request failed", err), nil
28+
}
29+
defer resp.Body.Close()
30+
31+
body, err := io.ReadAll(resp.Body)
32+
if err != nil {
33+
return mcp.NewToolResultErrorFromErr("Failed to read response body", err), nil
34+
}
35+
36+
if resp.StatusCode >= 400 {
37+
return mcp.NewToolResultError(fmt.Sprintf("API error: %s", body)), nil
38+
}
39+
// Use properly typed response
40+
var result map[string]interface{}
41+
if err := json.Unmarshal(body, &result); err != nil {
42+
// Fallback to raw text if unmarshaling fails
43+
return mcp.NewToolResultText(string(body)), nil
44+
}
45+
46+
prettyJSON, err := json.MarshalIndent(result, "", " ")
47+
if err != nil {
48+
return mcp.NewToolResultErrorFromErr("Failed to format JSON", err), nil
49+
}
50+
51+
return mcp.NewToolResultText(string(prettyJSON)), nil
52+
}
53+
}
54+
55+
func CreateGetTool(cfg *config.APIConfig) models.Tool {
56+
tool := mcp.NewTool("get_",
57+
mcp.WithDescription("Get api"),
58+
)
59+
60+
return models.Tool{
61+
Definition: tool,
62+
Handler: GetHandler(cfg),
63+
}
64+
}

MCP/tools/auth/head_basic_auth.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package tools
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"io"
8+
"net/http"
9+
10+
"github.com/input-api/mcp-server/config"
11+
"github.com/input-api/mcp-server/models"
12+
"github.com/mark3labs/mcp-go/mcp"
13+
)
14+
15+
func Head_basic_authHandler(cfg *config.APIConfig) func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
16+
return func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
17+
url := fmt.Sprintf("%sBASIC_AUTH", cfg.BaseURL)
18+
req, err := http.NewRequest("HEAD", url, nil)
19+
if err != nil {
20+
return mcp.NewToolResultErrorFromErr("Failed to create request", err), nil
21+
}
22+
// No authentication required for this endpoint
23+
req.Header.Set("Accept", "application/json")
24+
25+
resp, err := http.DefaultClient.Do(req)
26+
if err != nil {
27+
return mcp.NewToolResultErrorFromErr("Request failed", err), nil
28+
}
29+
defer resp.Body.Close()
30+
31+
body, err := io.ReadAll(resp.Body)
32+
if err != nil {
33+
return mcp.NewToolResultErrorFromErr("Failed to read response body", err), nil
34+
}
35+
36+
if resp.StatusCode >= 400 {
37+
return mcp.NewToolResultError(fmt.Sprintf("API error: %s", body)), nil
38+
}
39+
// Use properly typed response
40+
var result string
41+
if err := json.Unmarshal(body, &result); err != nil {
42+
// Fallback to raw text if unmarshaling fails
43+
return mcp.NewToolResultText(string(body)), nil
44+
}
45+
46+
prettyJSON, err := json.MarshalIndent(result, "", " ")
47+
if err != nil {
48+
return mcp.NewToolResultErrorFromErr("Failed to format JSON", err), nil
49+
}
50+
51+
return mcp.NewToolResultText(string(prettyJSON)), nil
52+
}
53+
}
54+
55+
func CreateHead_basic_authTool(cfg *config.APIConfig) models.Tool {
56+
tool := mcp.NewTool("head_BASIC_AUTH",
57+
mcp.WithDescription("Get Basic Auth Header"),
58+
)
59+
60+
return models.Tool{
61+
Definition: tool,
62+
Handler: Head_basic_authHandler(cfg),
63+
}
64+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package tools
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"io"
8+
"net/http"
9+
10+
"github.com/input-api/mcp-server/config"
11+
"github.com/input-api/mcp-server/models"
12+
"github.com/mark3labs/mcp-go/mcp"
13+
)
14+
15+
func Head_bearer_tokenHandler(cfg *config.APIConfig) func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
16+
return func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
17+
url := fmt.Sprintf("%sBEARER_TOKEN", cfg.BaseURL)
18+
req, err := http.NewRequest("HEAD", url, nil)
19+
if err != nil {
20+
return mcp.NewToolResultErrorFromErr("Failed to create request", err), nil
21+
}
22+
// No authentication required for this endpoint
23+
req.Header.Set("Accept", "application/json")
24+
25+
resp, err := http.DefaultClient.Do(req)
26+
if err != nil {
27+
return mcp.NewToolResultErrorFromErr("Request failed", err), nil
28+
}
29+
defer resp.Body.Close()
30+
31+
body, err := io.ReadAll(resp.Body)
32+
if err != nil {
33+
return mcp.NewToolResultErrorFromErr("Failed to read response body", err), nil
34+
}
35+
36+
if resp.StatusCode >= 400 {
37+
return mcp.NewToolResultError(fmt.Sprintf("API error: %s", body)), nil
38+
}
39+
// Use properly typed response
40+
var result string
41+
if err := json.Unmarshal(body, &result); err != nil {
42+
// Fallback to raw text if unmarshaling fails
43+
return mcp.NewToolResultText(string(body)), nil
44+
}
45+
46+
prettyJSON, err := json.MarshalIndent(result, "", " ")
47+
if err != nil {
48+
return mcp.NewToolResultErrorFromErr("Failed to format JSON", err), nil
49+
}
50+
51+
return mcp.NewToolResultText(string(prettyJSON)), nil
52+
}
53+
}
54+
55+
func CreateHead_bearer_tokenTool(cfg *config.APIConfig) models.Tool {
56+
tool := mcp.NewTool("head_BEARER_TOKEN",
57+
mcp.WithDescription("Get Bearer Token"),
58+
)
59+
60+
return models.Tool{
61+
Definition: tool,
62+
Handler: Head_bearer_tokenHandler(cfg),
63+
}
64+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package tools
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"io"
8+
"net/http"
9+
10+
"github.com/input-api/mcp-server/config"
11+
"github.com/input-api/mcp-server/models"
12+
"github.com/mark3labs/mcp-go/mcp"
13+
)
14+
15+
func Head_api_keyHandler(cfg *config.APIConfig) func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
16+
return func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
17+
url := fmt.Sprintf("%sAPI_KEY", cfg.BaseURL)
18+
req, err := http.NewRequest("HEAD", url, nil)
19+
if err != nil {
20+
return mcp.NewToolResultErrorFromErr("Failed to create request", err), nil
21+
}
22+
// No authentication required for this endpoint
23+
req.Header.Set("Accept", "application/json")
24+
25+
resp, err := http.DefaultClient.Do(req)
26+
if err != nil {
27+
return mcp.NewToolResultErrorFromErr("Request failed", err), nil
28+
}
29+
defer resp.Body.Close()
30+
31+
body, err := io.ReadAll(resp.Body)
32+
if err != nil {
33+
return mcp.NewToolResultErrorFromErr("Failed to read response body", err), nil
34+
}
35+
36+
if resp.StatusCode >= 400 {
37+
return mcp.NewToolResultError(fmt.Sprintf("API error: %s", body)), nil
38+
}
39+
// Use properly typed response
40+
var result string
41+
if err := json.Unmarshal(body, &result); err != nil {
42+
// Fallback to raw text if unmarshaling fails
43+
return mcp.NewToolResultText(string(body)), nil
44+
}
45+
46+
prettyJSON, err := json.MarshalIndent(result, "", " ")
47+
if err != nil {
48+
return mcp.NewToolResultErrorFromErr("Failed to format JSON", err), nil
49+
}
50+
51+
return mcp.NewToolResultText(string(prettyJSON)), nil
52+
}
53+
}
54+
55+
func CreateHead_api_keyTool(cfg *config.APIConfig) models.Tool {
56+
tool := mcp.NewTool("head_API_KEY",
57+
mcp.WithDescription("Get API Key from Request Header"),
58+
)
59+
60+
return models.Tool{
61+
Definition: tool,
62+
Handler: Head_api_keyHandler(cfg),
63+
}
64+
}

0 commit comments

Comments
 (0)