poker-mcp 1.2.5 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/package.json +1 -1
- package/src/config/ConfigManager.js +9 -2
- package/src/mcp/server.js +2 -1
- package/src/mcp_server_stdio_v4.js +47 -45
- package/src/services/DataManager.js +15 -12
- package/src/utils/logger.js +29 -24
- package/src/utils/paths.js +24 -0
package/README.md
CHANGED
|
@@ -53,10 +53,10 @@ npx poker-mcp
|
|
|
53
53
|
**POKER_INSTALL_PATH環境変数**(オプション):
|
|
54
54
|
```bash
|
|
55
55
|
# Windowsの場合(コマンドプロンプト)
|
|
56
|
-
set POKER_INSTALL_PATH=C
|
|
56
|
+
set POKER_INSTALL_PATH=C:/Poker
|
|
57
57
|
|
|
58
58
|
# Windowsの場合(PowerShell)
|
|
59
|
-
$env:POKER_INSTALL_PATH="C
|
|
59
|
+
$env:POKER_INSTALL_PATH="C:/Poker"
|
|
60
60
|
|
|
61
61
|
# Linux/macOSの場合
|
|
62
62
|
export POKER_INSTALL_PATH="/usr/local/share/poker"
|
|
@@ -86,7 +86,7 @@ export POKER_INSTALL_PATH="/usr/local/share/poker"
|
|
|
86
86
|
"command": "node",
|
|
87
87
|
"args": ["C:\\Users\\yoshi\\Desktop\\poker_mcp\\src\\mcp_server_stdio_v4.js"],
|
|
88
88
|
"env": {
|
|
89
|
-
"POKER_INSTALL_PATH": "C:/
|
|
89
|
+
"POKER_INSTALL_PATH": "C:/Poker"
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
}
|
|
@@ -101,7 +101,7 @@ export POKER_INSTALL_PATH="/usr/local/share/poker"
|
|
|
101
101
|
"command": "npx",
|
|
102
102
|
"args": ["poker-mcp"],
|
|
103
103
|
"env": {
|
|
104
|
-
"POKER_INSTALL_PATH": "C:/
|
|
104
|
+
"POKER_INSTALL_PATH": "C:/Poker"
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "poker-mcp",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
4
4
|
"description": "YAML-based input file management tool for radiation shielding calculation code POKER with MCP support - Enhanced with collision detection, daughter nuclide auto-completion, and environment variable support",
|
|
5
5
|
"main": "src/mcp_server_stdio_v4.js",
|
|
6
6
|
"type": "module",
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
// src/config/ConfigManager.js
|
|
2
2
|
import fs from 'fs/promises';
|
|
3
3
|
import path from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
4
5
|
import { logger } from '../utils/logger.js';
|
|
5
6
|
import { DataError } from '../utils/errors.js';
|
|
7
|
+
import { USER_CONFIG } from '../utils/paths.js';
|
|
8
|
+
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
6
11
|
|
|
7
12
|
export class ConfigManager {
|
|
8
13
|
constructor() {
|
|
9
14
|
this.config = null;
|
|
10
|
-
|
|
11
|
-
this.
|
|
15
|
+
// default.json はパッケージ同梱なので __dirname 基準の絶対パスで解決
|
|
16
|
+
this.configPath = path.join(__dirname, 'default.json');
|
|
17
|
+
// ユーザー設定は POKER_MCP_HOME 配下に置く
|
|
18
|
+
this.userConfigPath = USER_CONFIG;
|
|
12
19
|
}
|
|
13
20
|
|
|
14
21
|
async load() {
|
package/src/mcp/server.js
CHANGED
|
@@ -7,9 +7,10 @@ import { allTools } from './tools/index.js';
|
|
|
7
7
|
import { createAllHandlers } from './handlers/index.js';
|
|
8
8
|
import { safeExecute } from './middleware/errorHandler.js';
|
|
9
9
|
import { logger } from '../utils/logger.js';
|
|
10
|
+
import { YAML_FILE, PENDING_FILE } from '../utils/paths.js';
|
|
10
11
|
|
|
11
12
|
export class PokerMcpServer {
|
|
12
|
-
constructor(yamlFile =
|
|
13
|
+
constructor(yamlFile = YAML_FILE, pendingFile = PENDING_FILE) {
|
|
13
14
|
this.server = new Server(
|
|
14
15
|
{
|
|
15
16
|
name: 'poker-mcp',
|
|
@@ -1,45 +1,47 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// mcp_server_stdio_v4.js - MCP専用版(stdout汚染防止)
|
|
3
|
-
import { PokerMcpServer } from './mcp/server.js';
|
|
4
|
-
import { logger } from './utils/logger.js';
|
|
5
|
-
|
|
6
|
-
async function main() {
|
|
7
|
-
try {
|
|
8
|
-
const server = new PokerMcpServer();
|
|
9
|
-
await server.initialize();
|
|
10
|
-
await server.start();
|
|
11
|
-
} catch (error) {
|
|
12
|
-
logger.error('サーバー起動失敗', { error: error.message });
|
|
13
|
-
//
|
|
14
|
-
process.
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
process.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
process.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// mcp_server_stdio_v4.js - MCP専用版(stdout汚染防止)
|
|
3
|
+
import { PokerMcpServer } from './mcp/server.js';
|
|
4
|
+
import { logger } from './utils/logger.js';
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
try {
|
|
8
|
+
const server = new PokerMcpServer();
|
|
9
|
+
await server.initialize();
|
|
10
|
+
await server.start();
|
|
11
|
+
} catch (error) {
|
|
12
|
+
logger.error('サーバー起動失敗', { error: error.message });
|
|
13
|
+
// stdoutは汚染禁止だが、stderrへの出力は許容(Claude Desktopがログに記録する)
|
|
14
|
+
process.stderr.write(`[poker-mcp] Fatal: ${error.message}\n`);
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 未処理の例外とプロミス拒否のハンドリング
|
|
20
|
+
process.on('uncaughtException', (error) => {
|
|
21
|
+
logger.error('Uncaught Exception', { error: error.message, stack: error.stack });
|
|
22
|
+
process.stderr.write(`[poker-mcp] Uncaught Exception: ${error.message}\n`);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
27
|
+
logger.error('Unhandled Rejection', { reason: reason?.message || reason, promise });
|
|
28
|
+
process.stderr.write(`[poker-mcp] Unhandled Rejection: ${reason?.message || reason}\n`);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// グレースフルシャットダウン
|
|
33
|
+
process.on('SIGINT', () => {
|
|
34
|
+
logger.info('SIGINT受信、サーバーを終了します');
|
|
35
|
+
process.exit(0);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
process.on('SIGTERM', () => {
|
|
39
|
+
logger.info('SIGTERM受信、サーバーを終了します');
|
|
40
|
+
process.exit(0);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
main().catch((error) => {
|
|
44
|
+
logger.error('メイン関数エラー', { error: error.message });
|
|
45
|
+
process.stderr.write(`[poker-mcp] Main error: ${error.message}\n`);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
});
|
|
@@ -7,13 +7,16 @@ import { DataError } from '../utils/errors.js';
|
|
|
7
7
|
import CollisionDetector from '../utils/CollisionDetector.js';
|
|
8
8
|
import NuclideManager from '../utils/NuclideManager.js';
|
|
9
9
|
import EnhancedValidator from '../utils/EnhancedValidator.js';
|
|
10
|
+
import { BACKUPS_DIR, LOGS_DIR, TASKS_DIR, DATA_DIR, NDX_FILE,
|
|
11
|
+
YAML_FILE, PENDING_FILE } from '../utils/paths.js';
|
|
10
12
|
|
|
11
13
|
export class SafeDataManager {
|
|
12
14
|
constructor(yamlFile, pendingFile) {
|
|
13
|
-
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
16
|
-
this.
|
|
15
|
+
// 引数が省略された場合は paths.js の絶対パスをデフォルトとして使用
|
|
16
|
+
this.yamlFile = yamlFile ?? YAML_FILE;
|
|
17
|
+
this.pendingFile = pendingFile ?? PENDING_FILE;
|
|
18
|
+
this.backupDir = BACKUPS_DIR;
|
|
19
|
+
this.maxBackups = 10;
|
|
17
20
|
this.data = null;
|
|
18
21
|
this.pendingChanges = [];
|
|
19
22
|
|
|
@@ -24,11 +27,11 @@ export class SafeDataManager {
|
|
|
24
27
|
max_auto_corrections: 10
|
|
25
28
|
});
|
|
26
29
|
|
|
27
|
-
//
|
|
30
|
+
// 核種管理の初期化(絶対パスを使用)
|
|
28
31
|
this.nuclideManager = new NuclideManager({
|
|
29
32
|
contribution_threshold: 0.05,
|
|
30
33
|
user_confirmation: true,
|
|
31
|
-
database_file:
|
|
34
|
+
database_file: NDX_FILE
|
|
32
35
|
});
|
|
33
36
|
|
|
34
37
|
// 強化検証の初期化
|
|
@@ -41,11 +44,11 @@ export class SafeDataManager {
|
|
|
41
44
|
|
|
42
45
|
async initialize() {
|
|
43
46
|
try {
|
|
44
|
-
//
|
|
45
|
-
await fs.mkdir(
|
|
46
|
-
await fs.mkdir(
|
|
47
|
-
await fs.mkdir(
|
|
48
|
-
await fs.mkdir(
|
|
47
|
+
// 必要なフォルダをすべて作成(絶対パスで権限エラーを回避)
|
|
48
|
+
await fs.mkdir(BACKUPS_DIR, { recursive: true }); // backups
|
|
49
|
+
await fs.mkdir(LOGS_DIR, { recursive: true }); // logs
|
|
50
|
+
await fs.mkdir(TASKS_DIR, { recursive: true }); // tasks
|
|
51
|
+
await fs.mkdir(DATA_DIR, { recursive: true }); // data
|
|
49
52
|
|
|
50
53
|
// 必要なデータファイルをコピー
|
|
51
54
|
await this.ensureDataFiles();
|
|
@@ -70,7 +73,7 @@ export class SafeDataManager {
|
|
|
70
73
|
// 新規メソッド: 必要なデータファイルの確保
|
|
71
74
|
async ensureDataFiles() {
|
|
72
75
|
try {
|
|
73
|
-
const targetFile =
|
|
76
|
+
const targetFile = NDX_FILE; // 絶対パスを使用
|
|
74
77
|
|
|
75
78
|
// ターゲットファイルの存在チェック
|
|
76
79
|
try {
|
package/src/utils/logger.js
CHANGED
|
@@ -1,24 +1,29 @@
|
|
|
1
|
-
// utils/logger.js - MCP専用版(stdout汚染防止)
|
|
2
|
-
import winston from 'winston';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
// utils/logger.js - MCP専用版(stdout汚染防止)
|
|
2
|
+
import winston from 'winston';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import { LOGS_DIR } from './paths.js';
|
|
6
|
+
|
|
7
|
+
// ログディレクトリを起動時に確実に作成(相対パス問題を回避)
|
|
8
|
+
fs.mkdirSync(LOGS_DIR, { recursive: true });
|
|
9
|
+
|
|
10
|
+
const logger = winston.createLogger({
|
|
11
|
+
level: process.env.LOG_LEVEL || 'info',
|
|
12
|
+
format: winston.format.combine(
|
|
13
|
+
winston.format.timestamp(),
|
|
14
|
+
winston.format.errors({ stack: true }),
|
|
15
|
+
winston.format.json()
|
|
16
|
+
),
|
|
17
|
+
transports: [
|
|
18
|
+
new winston.transports.File({
|
|
19
|
+
filename: path.join(LOGS_DIR, 'error.log'),
|
|
20
|
+
level: 'error'
|
|
21
|
+
}),
|
|
22
|
+
new winston.transports.File({
|
|
23
|
+
filename: path.join(LOGS_DIR, 'combined.log')
|
|
24
|
+
})
|
|
25
|
+
// Console transportは削除(MCPサーバーではstdout汚染禁止)
|
|
26
|
+
]
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export { logger };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// utils/paths.js - 実行時データの格納先を一元管理
|
|
2
|
+
//
|
|
3
|
+
// 優先順位:
|
|
4
|
+
// 1. 環境変数 POKER_MCP_HOME が設定されていれば、その値を使用
|
|
5
|
+
// 2. 未設定なら os.homedir()/.poker-mcp/ をデフォルトとする
|
|
6
|
+
//
|
|
7
|
+
// claude_desktop_config.json での設定例:
|
|
8
|
+
// "env": { "POKER_MCP_HOME": "C:\\Users\\yoshi\\poker_mcp_workspace" }
|
|
9
|
+
//
|
|
10
|
+
import path from 'path';
|
|
11
|
+
import os from 'os';
|
|
12
|
+
|
|
13
|
+
export const BASE_DIR = process.env.POKER_MCP_HOME
|
|
14
|
+
?? path.join(os.homedir(), '.poker-mcp');
|
|
15
|
+
|
|
16
|
+
export const LOGS_DIR = path.join(BASE_DIR, 'logs');
|
|
17
|
+
export const TASKS_DIR = path.join(BASE_DIR, 'tasks');
|
|
18
|
+
export const BACKUPS_DIR = path.join(BASE_DIR, 'backups');
|
|
19
|
+
export const DATA_DIR = path.join(BASE_DIR, 'data');
|
|
20
|
+
|
|
21
|
+
export const YAML_FILE = path.join(TASKS_DIR, 'poker.yaml');
|
|
22
|
+
export const PENDING_FILE = path.join(TASKS_DIR, 'pending_changes.json');
|
|
23
|
+
export const NDX_FILE = path.join(DATA_DIR, 'ICRP-07.NDX');
|
|
24
|
+
export const USER_CONFIG = path.join(BASE_DIR, 'config.json');
|