@@ -17,6 +17,7 @@ type MCPServer struct {
1717 toolMap map [string ]Tool
1818 in io.Reader
1919 out io.Writer
20+ version string
2021}
2122
2223type Tool struct {
@@ -52,11 +53,20 @@ func NewMCPServerWithIO(c *client.Client, in io.Reader, out io.Writer) *MCPServe
5253 toolMap : make (map [string ]Tool ),
5354 in : in ,
5455 out : out ,
56+ version : "dev" ,
5557 }
5658 s .registerTools ()
5759 return s
5860}
5961
62+ // SetVersion overrides the version reported in the MCP initialize handshake.
63+ // main.go calls this with the ldflags-injected build version.
64+ func (s * MCPServer ) SetVersion (v string ) {
65+ if v != "" {
66+ s .version = v
67+ }
68+ }
69+
6070func (s * MCPServer ) registerTools () {
6171 s .tools = []Tool {
6272 // Tab management
@@ -80,6 +90,12 @@ func (s *MCPServer) registerTools() {
8090 {Name : "codex_reload" , Description : "Reload a tab" ,
8191 InputSchema : schema (`{"type":"object","properties":{"tab_id":{"type":"string"}},"required":["tab_id"]}` ),
8292 Handler : s .handleReload },
93+ {Name : "codex_navigate_back" , Description : "Navigate a tab back one entry in its history" ,
94+ InputSchema : schema (`{"type":"object","properties":{"tab_id":{"type":"string"}},"required":["tab_id"]}` ),
95+ Handler : s .handleNavigateBack },
96+ {Name : "codex_navigate_forward" , Description : "Navigate a tab forward one entry in its history" ,
97+ InputSchema : schema (`{"type":"object","properties":{"tab_id":{"type":"string"}},"required":["tab_id"]}` ),
98+ Handler : s .handleNavigateForward },
8399 {Name : "codex_wait_for_load" , Description : "Poll document.readyState until it equals \" complete\" or timeout (ms) elapses. Useful after navigation on slow pages." ,
84100 InputSchema : schema (`{"type":"object","properties":{"tab_id":{"type":"string"},"timeout_ms":{"type":"number","description":"Timeout in milliseconds. Defaults to 10000."}},"required":["tab_id"]}` ),
85101 Handler : s .handleWaitForLoad },
@@ -182,7 +198,7 @@ func (s *MCPServer) handleMessage(req struct {
182198 s .writeResult (req .ID , map [string ]interface {}{
183199 "protocolVersion" : "2024-11-05" ,
184200 "capabilities" : map [string ]interface {}{"tools" : map [string ]interface {}{}},
185- "serverInfo" : map [string ]interface {}{"name" : "codex-browser-bridge" , "version" : "0.1.0" },
201+ "serverInfo" : map [string ]interface {}{"name" : "codex-browser-bridge" , "version" : s . version },
186202 })
187203 case "tools/list" :
188204 tools := make ([]map [string ]interface {}, len (s .tools ))
@@ -324,6 +340,28 @@ func (s *MCPServer) handleReload(args json.RawMessage) ([]Content, error) {
324340 return textContent (fmt .Sprintf ("Reloaded tab %s" , p .TabID )), nil
325341}
326342
343+ func (s * MCPServer ) handleNavigateBack (args json.RawMessage ) ([]Content , error ) {
344+ var p struct {
345+ TabID string `json:"tab_id"`
346+ }
347+ json .Unmarshal (args , & p )
348+ if err := s .client .NavigateBack (p .TabID ); err != nil {
349+ return nil , err
350+ }
351+ return textContent (fmt .Sprintf ("Navigated tab %s back" , p .TabID )), nil
352+ }
353+
354+ func (s * MCPServer ) handleNavigateForward (args json.RawMessage ) ([]Content , error ) {
355+ var p struct {
356+ TabID string `json:"tab_id"`
357+ }
358+ json .Unmarshal (args , & p )
359+ if err := s .client .NavigateForward (p .TabID ); err != nil {
360+ return nil , err
361+ }
362+ return textContent (fmt .Sprintf ("Navigated tab %s forward" , p .TabID )), nil
363+ }
364+
327365func (s * MCPServer ) handleWaitForLoad (args json.RawMessage ) ([]Content , error ) {
328366 var p struct {
329367 TabID string `json:"tab_id"`
0 commit comments