11package mcpserver
22
33import (
4+ "bytes"
45 "context"
56 _ "embed"
67 "encoding/json"
@@ -115,6 +116,8 @@ func init() {
115116 EnvironmentAddServiceTool ,
116117
117118 EnvironmentCheckpointTool ,
119+ EnvironmentLogTool ,
120+ EnvironmentDiffTool ,
118121 )
119122}
120123
@@ -816,3 +819,80 @@ Supported schemas are:
816819 return mcp .NewToolResultText (fmt .Sprintf ("Service added and started successfully: %s" , string (output ))), nil
817820 },
818821}
822+
823+ var EnvironmentLogTool = & Tool {
824+ Definition : mcp .NewTool ("environment_log" ,
825+ mcp .WithDescription ("View the development history of an environment, showing all commits made by the agent plus command execution notes." ),
826+ mcp .WithString ("explanation" ,
827+ mcp .Description ("One sentence explanation for why this environment log is being viewed." ),
828+ ),
829+ mcp .WithString ("environment_source" ,
830+ mcp .Description ("Absolute path to the source git repository for the environment." ),
831+ mcp .Required (),
832+ ),
833+ mcp .WithString ("environment_id" ,
834+ mcp .Description ("The ID of the environment to view the log for." ),
835+ mcp .Required (),
836+ ),
837+ mcp .WithBoolean ("patch" ,
838+ mcp .Description ("Include code patches in the output (default: false)." ),
839+ ),
840+ ),
841+ Handler : func (ctx context.Context , request mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
842+ repo , err := openRepository (ctx , request )
843+ if err != nil {
844+ return mcp .NewToolResultErrorFromErr ("unable to open the repository" , err ), nil
845+ }
846+
847+ envID , err := request .RequireString ("environment_id" )
848+ if err != nil {
849+ return nil , err
850+ }
851+
852+ patch := request .GetBool ("patch" , false )
853+
854+ var buf bytes.Buffer
855+ // MCP tools always show full history (no branch comparison)
856+ if err := repo .Log (ctx , envID , patch , "" , & buf ); err != nil {
857+ return mcp .NewToolResultErrorFromErr ("failed to get environment log" , err ), nil
858+ }
859+
860+ return mcp .NewToolResultText (buf .String ()), nil
861+ },
862+ }
863+
864+ var EnvironmentDiffTool = & Tool {
865+ Definition : mcp .NewTool ("environment_diff" ,
866+ mcp .WithDescription ("View the cumulative changes made in an environment from its creation point, showing all code modifications as a unified diff." ),
867+ mcp .WithString ("explanation" ,
868+ mcp .Description ("One sentence explanation for why this environment diff is being viewed." ),
869+ ),
870+ mcp .WithString ("environment_source" ,
871+ mcp .Description ("Absolute path to the source git repository for the environment." ),
872+ mcp .Required (),
873+ ),
874+ mcp .WithString ("environment_id" ,
875+ mcp .Description ("The ID of the environment to view the diff for." ),
876+ mcp .Required (),
877+ ),
878+ ),
879+ Handler : func (ctx context.Context , request mcp.CallToolRequest ) (* mcp.CallToolResult , error ) {
880+ repo , err := openRepository (ctx , request )
881+ if err != nil {
882+ return mcp .NewToolResultErrorFromErr ("unable to open the repository" , err ), nil
883+ }
884+
885+ envID , err := request .RequireString ("environment_id" )
886+ if err != nil {
887+ return nil , err
888+ }
889+
890+ var buf bytes.Buffer
891+ // MCP tools always show full diff (no branch comparison)
892+ if err := repo .Diff (ctx , envID , "" , & buf ); err != nil {
893+ return mcp .NewToolResultErrorFromErr ("failed to get environment diff" , err ), nil
894+ }
895+
896+ return mcp .NewToolResultText (buf .String ()), nil
897+ },
898+ }
0 commit comments