@@ -20,11 +20,12 @@ import (
2020
2121// session holds the active WebKit client and collectors.
2222type session struct {
23- mu sync.Mutex
24- client * webkit.Client
25- networkMonitor * tools.NetworkMonitor
26- consoleCollector * tools.ConsoleCollector
27- timelineCollector * tools.TimelineCollector
23+ mu sync.Mutex
24+ client * webkit.Client
25+ networkMonitor * tools.NetworkMonitor
26+ consoleCollector * tools.ConsoleCollector
27+ timelineCollector * tools.TimelineCollector
28+ interceptionCollector * tools.InterceptionCollector
2829}
2930
3031var sess session
@@ -41,7 +42,7 @@ func getClient(ctx context.Context) (*webkit.Client, error) {
4142func main () {
4243 server := mcp .NewServer (& mcp.Implementation {
4344 Name : "iwdp-mcp" ,
44- Version : "0.3.1 " ,
45+ Version : "0.3.2 " ,
4546 }, nil )
4647
4748 registerTools (server )
@@ -557,6 +558,7 @@ func registerTools(server *mcp.Server) {
557558 sess .networkMonitor = nil
558559 sess .consoleCollector = nil
559560 sess .timelineCollector = nil
561+ sess .interceptionCollector = nil
560562 sess .mu .Unlock ()
561563
562564 if oldClient != nil {
@@ -973,33 +975,76 @@ func registerTools(server *mcp.Server) {
973975 })
974976
975977 mcp .AddTool (server , & mcp.Tool {
976- Name : "set_request_interception" , Description : "Enable or disable request interception" ,
978+ Name : "set_request_interception" , Description : "Enable or disable request interception. When enabled, intercepted requests appear in list_intercepted_requests and must be continued or responded to. " ,
977979 }, func (ctx context.Context , req * mcp.CallToolRequest , input SetRequestInterceptionInput ) (* mcp.CallToolResult , any , error ) {
978980 c , err := getClient (ctx )
979981 if err != nil {
980982 return nil , OKOutput {}, err
981983 }
982- return nil , ok (), tools .SetRequestInterception (ctx , c , input .Enabled )
984+ if input .Enabled {
985+ sess .mu .Lock ()
986+ if sess .interceptionCollector == nil {
987+ sess .interceptionCollector = tools .NewInterceptionCollector ()
988+ }
989+ ic := sess .interceptionCollector
990+ sess .mu .Unlock ()
991+ return nil , ok (), ic .Start (ctx , c )
992+ }
993+ sess .mu .Lock ()
994+ ic := sess .interceptionCollector
995+ sess .mu .Unlock ()
996+ if ic != nil {
997+ return nil , ok (), ic .Stop (ctx , c )
998+ }
999+ return nil , ok (), nil
1000+ })
1001+
1002+ mcp .AddTool (server , & mcp.Tool {
1003+ Name : "list_intercepted_requests" , Description : "List pending intercepted requests. Each has a request_id to use with intercept_continue or intercept_with_response." ,
1004+ }, func (ctx context.Context , req * mcp.CallToolRequest , _ EmptyInput ) (* mcp.CallToolResult , any , error ) {
1005+ sess .mu .Lock ()
1006+ ic := sess .interceptionCollector
1007+ sess .mu .Unlock ()
1008+ if ic == nil {
1009+ return nil , RawOutput {Result : []any {}}, nil
1010+ }
1011+ return nil , RawOutput {Result : ic .GetPending ()}, nil
9831012 })
9841013
9851014 mcp .AddTool (server , & mcp.Tool {
986- Name : "intercept_continue" , Description : "Continue an intercepted request" ,
1015+ Name : "intercept_continue" , Description : "Continue an intercepted request without modification " ,
9871016 }, func (ctx context.Context , req * mcp.CallToolRequest , input InterceptContinueInput ) (* mcp.CallToolResult , any , error ) {
9881017 c , err := getClient (ctx )
9891018 if err != nil {
9901019 return nil , OKOutput {}, err
9911020 }
992- return nil , ok (), tools .InterceptContinue (ctx , c , input .RequestID )
1021+ err = tools .InterceptContinue (ctx , c , input .RequestID )
1022+ if err == nil {
1023+ sess .mu .Lock ()
1024+ if sess .interceptionCollector != nil {
1025+ sess .interceptionCollector .RemovePending (input .RequestID )
1026+ }
1027+ sess .mu .Unlock ()
1028+ }
1029+ return nil , ok (), err
9931030 })
9941031
9951032 mcp .AddTool (server , & mcp.Tool {
996- Name : "intercept_with_response" , Description : "Respond to an intercepted request with custom response" ,
1033+ Name : "intercept_with_response" , Description : "Respond to an intercepted request with a custom response" ,
9971034 }, func (ctx context.Context , req * mcp.CallToolRequest , input InterceptWithResponseInput ) (* mcp.CallToolResult , any , error ) {
9981035 c , err := getClient (ctx )
9991036 if err != nil {
10001037 return nil , OKOutput {}, err
10011038 }
1002- return nil , ok (), tools .InterceptWithResponse (ctx , c , input .RequestID , input .StatusCode , input .Headers , input .Body )
1039+ err = tools .InterceptWithResponse (ctx , c , input .RequestID , input .StatusCode , input .Headers , input .Body )
1040+ if err == nil {
1041+ sess .mu .Lock ()
1042+ if sess .interceptionCollector != nil {
1043+ sess .interceptionCollector .RemovePending (input .RequestID )
1044+ }
1045+ sess .mu .Unlock ()
1046+ }
1047+ return nil , ok (), err
10031048 })
10041049
10051050 mcp .AddTool (server , & mcp.Tool {
0 commit comments