add via mcp

This commit is contained in:
2026-09-06 00:08:20 +07:00
parent daba1c244d
commit d8197fce73
8 changed files with 27 additions and 12 deletions
+1
View File
@@ -1099,6 +1099,7 @@ func (s *server) AddTeamAction(ctx context.Context, req *proto.AddTeamActionReq)
int(req.Id),
req.Password,
req.Code,
false,
)
if err != nil {
return &proto.AddTeamActionRsp{
+4 -3
View File
@@ -21,15 +21,16 @@ func NewActionsRepo(pool *pgxpool.Pool) *ActionsRepo {
}
}
func (r *ActionsRepo) AddAction(ctx context.Context, teamId int, code string) (int, error) {
func (r *ActionsRepo) AddAction(ctx context.Context, teamId int, code string, viaMCP bool) (int, error) {
id := 0
err := r.pool.QueryRow(
ctx,
`INSERT INTO actions (code, team_id)
VALUES ($1, $2)
`INSERT INTO actions (code, team_id, via_mcp)
VALUES ($1, $2, $3)
RETURNING id`,
code,
teamId,
viaMCP,
).Scan(&id)
if err != nil {
+2 -2
View File
@@ -234,7 +234,7 @@ func (s *GameService) GetTeamActions(ctx context.Context, teamId int, password s
return s.storyteller.GetStory(scenario.Story, actions), mapGame(game, s.domain), nil
}
func (s *GameService) AddTeamAction(ctx context.Context, teamId int, password string, actionCode string) error {
func (s *GameService) AddTeamAction(ctx context.Context, teamId int, password string, actionCode string, viaMCP bool) error {
team, err := s.teamsRepo.GetTeamByID(ctx, teamId)
if err != nil {
return err
@@ -244,7 +244,7 @@ func (s *GameService) AddTeamAction(ctx context.Context, teamId int, password st
return teams_repo.ErrTeamNotFound
}
_, err = s.actionsRepo.AddAction(ctx, teamId, actionCode)
_, err = s.actionsRepo.AddAction(ctx, teamId, actionCode, viaMCP)
if err != nil {
return err
}
+2 -2
View File
@@ -30,7 +30,7 @@ const defaultCallTimeout = 10 * time.Second
// без БД.
type GamePlayer interface {
GetTeamActions(ctx context.Context, teamId int, password string) (*storytelling.Story, *game_service.Game, error)
AddTeamAction(ctx context.Context, teamId int, password, actionCode string) error
AddTeamAction(ctx context.Context, teamId int, password, actionCode string, viaMCP bool) error
SubmitTeamAnswers(ctx context.Context, teamId int, password string, answers []game_service.Answer) error
}
@@ -261,7 +261,7 @@ func (s *MCPService) handleMakeMove(ctx context.Context, req mcp.CallToolRequest
ctx, cancel := context.WithTimeout(ctx, defaultCallTimeout)
defer cancel()
if err := s.game.AddTeamAction(ctx, int(teamID), password, code); err != nil {
if err := s.game.AddTeamAction(ctx, int(teamID), password, code, true); err != nil {
return mcp.NewToolResultError(fmt.Sprintf("make_move: %v", err)), nil
}
+11 -5
View File
@@ -17,9 +17,10 @@ import (
// fakeGamePlayer — мок GamePlayer с предзаданными историей, игрой и
// ошибками (реализует интерфейс GamePlayer, БД не нужна).
type fakeGamePlayer struct {
story *storytelling.Story
game *game_service.Game
err error
story *storytelling.Story
game *game_service.Game
err error
viaMCP bool
}
func (f *fakeGamePlayer) GetTeamActions(_ context.Context, teamID int, password string) (*storytelling.Story, *game_service.Game, error) {
@@ -29,7 +30,8 @@ func (f *fakeGamePlayer) GetTeamActions(_ context.Context, teamID int, password
return f.story, f.game, nil
}
func (f *fakeGamePlayer) AddTeamAction(_ context.Context, teamID int, password, code string) error {
func (f *fakeGamePlayer) AddTeamAction(_ context.Context, teamID int, password, code string, viaMCP bool) error {
f.viaMCP = viaMCP
if f.err != nil {
return f.err
}
@@ -295,7 +297,8 @@ func TestGetTeamStoryInvalidTeamID(t *testing.T) {
}
func TestMakeMove(t *testing.T) {
f := newMCPFixture(t, &fakeGamePlayer{story: defaultStory(), game: defaultGame()})
player := &fakeGamePlayer{story: defaultStory(), game: defaultGame()}
f := newMCPFixture(t, player)
got := f.call(t, "make_move", map[string]any{
"team_id": "10", // строка тоже принимается
@@ -305,6 +308,9 @@ func TestMakeMove(t *testing.T) {
if !strings.Contains(got, "entrance") {
t.Fatalf("make_move: %q; want updated story JSON", got)
}
if !player.viaMCP {
t.Fatal("make_move must mark the action as via MCP")
}
}
func TestMakeMoveActionError(t *testing.T) {