Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iwdp-mcp",
"version": "0.5.2",
"version": "0.5.3",
"description": "iOS Safari debugging via ios-webkit-debug-proxy — MCP server with full WebKit Inspector Protocol support",
"owner": {
"name": "nnemirovsky"
Expand Down
2 changes: 1 addition & 1 deletion .claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iwdp-mcp",
"version": "0.5.2",
"version": "0.5.3",
"description": "iOS Safari debugging via ios-webkit-debug-proxy — MCP server with full WebKit Inspector Protocol support",
"mcpServers": {
"iwdp-mcp": {
Expand Down
69 changes: 56 additions & 13 deletions cmd/iwdp-mcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/url"
"os"
"path/filepath"
"reflect"
"strings"
"sync"

Expand Down Expand Up @@ -65,7 +64,7 @@ func lookupInterceptStage(requestID string) string {
func main() {
server := mcp.NewServer(&mcp.Implementation{
Name: "iwdp-mcp",
Version: "0.5.2",
Version: "0.5.3",
}, nil)

registerTools(server)
Expand All @@ -76,23 +75,67 @@ func main() {
}

func addTool[In, Out any](s *mcp.Server, t *mcp.Tool, h mcp.ToolHandlerFor[In, Out]) {
if t.InputSchema == nil && isEmptyStructType(reflect.TypeFor[In]()) {
copy := *t
copy.InputSchema = emptyObjectInputSchema()
t = &copy
copy := *t
if copy.InputSchema == nil {
schema, err := jsonschema.For[In](nil)
if err != nil {
panic(fmt.Sprintf("AddTool: tool %q: input schema: %v", copy.Name, err))
}
copy.InputSchema = codexCompatibleInputSchema(copy.Name, schema)
} else {
copy.InputSchema = codexCompatibleInputSchema(copy.Name, copy.InputSchema)
}
mcp.AddTool(s, &copy, h)
}

func codexCompatibleInputSchema(toolName string, schema any) map[string]any {
data, err := json.Marshal(schema)
if err != nil {
panic(fmt.Sprintf("AddTool: tool %q: marshal input schema: %v", toolName, err))
}
mcp.AddTool(s, t, h)
var out map[string]any
if err := json.Unmarshal(data, &out); err != nil {
panic(fmt.Sprintf("AddTool: tool %q: unmarshal input schema: %v", toolName, err))
}
normalizeSchema(out)
return out
}

func isEmptyStructType(t reflect.Type) bool {
return t.Kind() == reflect.Struct && t.NumField() == 0
func normalizeSchema(schema any) {
switch s := schema.(type) {
case map[string]any:
for _, value := range s {
normalizeSchema(value)
}
if schemaTypeIncludes(s["type"], "object") {
if _, ok := s["properties"].(map[string]any); !ok {
s["properties"] = map[string]any{}
}
}
if schemaTypeIncludes(s["type"], "array") {
if _, ok := s["items"].(map[string]any); !ok {
s["items"] = map[string]any{}
}
}
case []any:
for _, value := range s {
normalizeSchema(value)
}
}
}

func emptyObjectInputSchema() *jsonschema.Schema {
return &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{},
func schemaTypeIncludes(value any, typ string) bool {
switch v := value.(type) {
case string:
return v == typ
case []any:
for _, item := range v {
if item == typ {
return true
}
}
}
return false
}

// --- Input/Output types for MCP tools ---
Expand Down
29 changes: 25 additions & 4 deletions cmd/iwdp-mcp/mcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -34,7 +35,7 @@ func TestServerCreationWithRegisterTools(t *testing.T) {
}
}

func TestToolInputSchemasIncludeProperties(t *testing.T) {
func TestToolInputSchemasAreCodexCompatible(t *testing.T) {
ctx := context.Background()
impl := &mcp.Implementation{Name: "iwdp-mcp-test", Version: "0.1.0"}
server := mcp.NewServer(impl, nil)
Expand Down Expand Up @@ -71,11 +72,31 @@ func TestToolInputSchemasIncludeProperties(t *testing.T) {
if err := json.Unmarshal(data, &schema); err != nil {
t.Fatalf("unmarshal input schema for %s: %v", tool.Name, err)
}
if schema["type"] == "object" {
if _, ok := schema["properties"]; !ok {
t.Fatalf("tool %s object input schema is missing properties: %s", tool.Name, data)
assertCodexCompatibleInputSchema(t, tool.Name, schema, tool.Name)
}
}

func assertCodexCompatibleInputSchema(t *testing.T, toolName string, schema any, path string) {
t.Helper()
switch s := schema.(type) {
case map[string]any:
if schemaTypeIncludes(s["type"], "object") {
if _, ok := s["properties"].(map[string]any); !ok {
t.Fatalf("tool %s object input schema is missing properties at %s", toolName, path)
}
}
if schemaTypeIncludes(s["type"], "array") {
if _, ok := s["items"].(map[string]any); !ok {
t.Fatalf("tool %s array input schema items is not an object at %s", toolName, path)
}
}
for key, value := range s {
assertCodexCompatibleInputSchema(t, toolName, value, path+"."+key)
}
case []any:
for i, value := range s {
assertCodexCompatibleInputSchema(t, toolName, value, fmt.Sprintf("%s[%d]", path, i))
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions e2e/simulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,10 @@ func TestSim_SetEmulatedConditions(t *testing.T) {
_ = monitor.Start(ctx, client)

if err := tools.SetEmulatedConditions(ctx, client, 100000); err != nil {
if strings.Contains(err.Error(), "'Network.setEmulatedConditions' was not found") {
t.Log("Network.setEmulatedConditions is not available in this WebKit/iwdp environment")
return
}
t.Fatalf("SetEmulatedConditions: %v", err)
}
// Reset
Expand Down
Loading