add mcp label

This commit is contained in:
2026-09-06 02:07:36 +07:00
parent 97ad956a6b
commit ef86674fce
9 changed files with 333 additions and 216 deletions
+21 -9
View File
@@ -206,32 +206,36 @@ func (s *GameService) GiveTeamApplications(ctx context.Context, teamId int, name
return s.applicationsRepo.UpdateApplicationStatus(ctx, teamId, name, "done")
}
func (s *GameService) GetTeamActions(ctx context.Context, teamId int, password string) (*storytelling.Story, *Game, error) {
func (s *GameService) GetTeamActions(ctx context.Context, teamId int, password string) (*storytelling.Story, *Game, []actions_repo.Action, error) {
team, err := s.teamsRepo.GetTeamByID(ctx, teamId)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
if team.Password != password {
return nil, nil, teams_repo.ErrTeamNotFound
return nil, nil, nil, teams_repo.ErrTeamNotFound
}
game, err := s.gamesRepo.GetGameByID(ctx, team.GameId)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
actions, err := s.actionsRepo.GetActionsByTeamID(ctx, teamId)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
scenario, err := s.scenarioService.GetFullScenarioByID(ctx, game.ScenarioId)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
return s.storyteller.GetStory(scenario.Story, actions), mapGame(game, s.domain), nil
codes := make([]string, len(actions))
for i, action := range actions {
codes[i] = action.Code
}
return s.storyteller.GetStory(scenario.Story, codes), mapGame(game, s.domain), actions, nil
}
func (s *GameService) AddTeamAction(ctx context.Context, teamId int, password string, actionCode string, viaMCP bool) error {
@@ -254,7 +258,7 @@ func (s *GameService) AddTeamAction(ctx context.Context, teamId int, password st
return err
}
actions, err := s.actionsRepo.GetActionsByTeamID(ctx, teamId)
actionDetails, err := s.actionsRepo.GetActionsByTeamID(ctx, teamId)
if err != nil {
return err
}
@@ -264,6 +268,10 @@ func (s *GameService) AddTeamAction(ctx context.Context, teamId int, password st
return err
}
actions := make([]string, len(actionDetails))
for i, action := range actionDetails {
actions[i] = action.Code
}
teamStory := s.storyteller.GetStory(scenario.Story, actions)
lastPlace := teamStory.Places[len(teamStory.Places)-1]
@@ -290,7 +298,7 @@ func (s *GameService) DeleteLastTeamAction(ctx context.Context, teamId int) erro
return err
}
actions, err := s.actionsRepo.GetActionsByTeamID(ctx, teamId)
actionDetails, err := s.actionsRepo.GetActionsByTeamID(ctx, teamId)
if err != nil {
return err
}
@@ -300,6 +308,10 @@ func (s *GameService) DeleteLastTeamAction(ctx context.Context, teamId int) erro
return err
}
actions := make([]string, len(actionDetails))
for i, action := range actionDetails {
actions[i] = action.Code
}
teamStory := s.storyteller.GetStory(scenario.Story, actions)
lastPlace := teamStory.Places[len(teamStory.Places)-1]
+6 -5
View File
@@ -15,6 +15,7 @@ import (
"time"
"evening_detective_server/internal/modules/storytelling"
"evening_detective_server/internal/repos/actions_repo"
"evening_detective_server/internal/services/game_service"
"github.com/mark3labs/mcp-go/mcp"
@@ -29,7 +30,7 @@ const defaultCallTimeout = 10 * time.Second
// *game_service.GameService; интерфейс позволяет тестировать сервис
// без БД.
type GamePlayer interface {
GetTeamActions(ctx context.Context, teamId int, password string) (*storytelling.Story, *game_service.Game, error)
GetTeamActions(ctx context.Context, teamId int, password string) (*storytelling.Story, *game_service.Game, []actions_repo.Action, 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
}
@@ -203,7 +204,7 @@ func (s *MCPService) handleConnect(ctx context.Context, req mcp.CallToolRequest)
ctx, cancel := context.WithTimeout(ctx, defaultCallTimeout)
defer cancel()
story, game, err := s.game.GetTeamActions(ctx, int(args.teamID), args.password)
story, game, _, err := s.game.GetTeamActions(ctx, int(args.teamID), args.password)
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("connect: %v", err)), nil
}
@@ -234,7 +235,7 @@ func (s *MCPService) handleGetTeamStory(ctx context.Context, req mcp.CallToolReq
ctx, cancel := context.WithTimeout(ctx, defaultCallTimeout)
defer cancel()
story, game, err := s.game.GetTeamActions(ctx, int(teamID), password)
story, game, _, err := s.game.GetTeamActions(ctx, int(teamID), password)
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("get_team_story: %v", err)), nil
}
@@ -265,7 +266,7 @@ func (s *MCPService) handleMakeMove(ctx context.Context, req mcp.CallToolRequest
return mcp.NewToolResultError(fmt.Sprintf("make_move: %v", err)), nil
}
story, game, err := s.game.GetTeamActions(ctx, int(teamID), password)
story, game, _, err := s.game.GetTeamActions(ctx, int(teamID), password)
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("make_move: %v", err)), nil
}
@@ -337,7 +338,7 @@ func (s *MCPService) handleSubmitAnswers(ctx context.Context, req mcp.CallToolRe
return mcp.NewToolResultError(fmt.Sprintf("submit_answers: %v", err)), nil
}
story, game, err := s.game.GetTeamActions(ctx, int(args.teamID), args.password)
story, game, _, err := s.game.GetTeamActions(ctx, int(args.teamID), args.password)
if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("submit_answers: %v", err)), nil
}
@@ -8,6 +8,7 @@ import (
"time"
"evening_detective_server/internal/modules/storytelling"
"evening_detective_server/internal/repos/actions_repo"
"evening_detective_server/internal/services/game_service"
"github.com/mark3labs/mcp-go/client"
@@ -23,11 +24,11 @@ type fakeGamePlayer struct {
viaMCP bool
}
func (f *fakeGamePlayer) GetTeamActions(_ context.Context, teamID int, password string) (*storytelling.Story, *game_service.Game, error) {
func (f *fakeGamePlayer) GetTeamActions(_ context.Context, teamID int, password string) (*storytelling.Story, *game_service.Game, []actions_repo.Action, error) {
if f.err != nil {
return nil, nil, f.err
return nil, nil, nil, f.err
}
return f.story, f.game, nil
return f.story, f.game, nil, nil
}
func (f *fakeGamePlayer) AddTeamAction(_ context.Context, teamID int, password, code string, viaMCP bool) error {