Skip to content

Commit 43afe23

Browse files
authored
Merge pull request #682 from craigk5n/feat/mcp-connection-help
feat(mcp): show endpoint URL + sample agent config; add per-user MCP tab
2 parents 5bc295e + 5796553 commit 43afe23

2 files changed

Lines changed: 61 additions & 15 deletions

File tree

admin.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,26 @@ function save_pref ( $prefs, $src ) {
789789
<div class="form-inline mt-1 mb-2"><label for="admin_MCP_CORS_CUSTOM" title="' . tooltip ( 'mcp-cors-custom-help' ) . '">'
790790
. translate ( 'Custom Origins (comma-separated)' ) . ':</label>
791791
<input type="text" size="40" name="admin_MCP_CORS_CUSTOM" id="admin_MCP_CORS_CUSTOM" value="'
792-
. htmlspecialchars ( (!empty($s['MCP_CORS_ORIGINS']) && $s['MCP_CORS_ORIGINS'] !== '*' && strpos($s['MCP_CORS_ORIGINS'], ',') !== false) ? $s['MCP_CORS_ORIGINS'] : '' ) . '" placeholder="https://example.com,https://another.com"></div>' )
792+
. htmlspecialchars ( (!empty($s['MCP_CORS_ORIGINS']) && $s['MCP_CORS_ORIGINS'] !== '*' && strpos($s['MCP_CORS_ORIGINS'], ',') !== false) ? $s['MCP_CORS_ORIGINS'] : '' ) . '" placeholder="https://example.com,https://another.com"></div>'
793+
. '<hr class="mt-2">'
794+
. '<div class="mt-1"><strong>' . translate ( 'MCP Endpoint URL' ) . ':</strong> '
795+
. '<code>' . htmlspecialchars ( getServerUrl() . 'mcp.php' ) . '</code></div>'
796+
. '<p class="mt-1"><small>'
797+
. translate ( 'Each user connects their AI agent with their own personal API token, generated on their Preferences MCP tab, where a ready-to-use sample configuration is shown.' )
798+
. '</small></p>'
799+
. '<details class="mt-1"><summary>' . translate ( 'Sample agent configuration' ) . '</summary>'
800+
. '<pre class="border rounded p-2 mt-1" style="white-space:pre-wrap;">'
801+
. htmlspecialchars ( '{
802+
"mcpServers": {
803+
"webcalendar": {
804+
"url": "' . getServerUrl() . 'mcp.php",
805+
"headers": {
806+
"X-MCP-Token": "YOUR_MCP_TOKEN"
807+
}
808+
}
809+
}
810+
}' )
811+
. '</pre></details>' )
793812
. '</fieldset>
794813
</div></div>
795814

pref.php

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ function save_pref( $prefs, $src) {
305305
<?php if ( $ALLOW_COLOR_CUSTOMIZATION == 'Y' ) { ?>
306306
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#colors"><?php etranslate('Colors');?></a></li>
307307
<?php } ?>
308+
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#mcp"><?php etranslate('MCP');?></a></li>
308309

309310
</ul>
310311

@@ -684,20 +685,6 @@ function save_pref( $prefs, $src) {
684685
<nobr><input class="form-control" type="text" name="pref_AUTO_REFRESH_TIME" size="3" value="<?php echo ( empty ( $prefarray['AUTO_REFRESH_TIME'] ) ? 0 : $prefarray['AUTO_REFRESH_TIME'] ); ?>"> <?php etranslate ( 'minutes' )?></nobr>
685686
</td></tr>
686687

687-
<tr><td data-toggle="tooltip" data-placement="top" title="<?php etooltip ("mcp-api-token-help");?>">
688-
<label for="mcp_api_token"><?php etranslate ( 'MCP API Token' )?>:</label></td><td class="form-inline mt-1">
689-
<?php if ( ! empty ( $mcp_new_token ) ) { ?>
690-
<input class="form-control" type="text" id="mcp_api_token_display" size="40" readonly value="<?php echo htmlspecialchars($mcp_new_token); ?>">
691-
<div class="text-warning mt-1"><?php etranslate('Copy this token now. For security it is stored hashed and cannot be shown again.'); ?></div>
692-
<?php } else { ?>
693-
<input class="form-control" type="text" id="mcp_api_token_display" size="40" readonly
694-
value="<?php echo $mcp_token_is_set ? '************************ (token set)' : ''; ?>">
695-
<?php } ?>
696-
<button type="button" class="btn btn-secondary ml-2" onclick="generateApiToken()"><?php etranslate('Generate New Token');?></button>
697-
<?php if ( $mcp_token_is_set || ! empty ( $mcp_new_token ) ) { ?>
698-
<button type="button" class="btn btn-outline-danger ml-2" onclick="clearApiToken()"><?php etranslate('Clear Token');?></button>
699-
<?php } ?>
700-
</td></tr>
701688
</table>
702689
</fieldset>
703690
</div>
@@ -902,6 +889,46 @@ function save_pref( $prefs, $src) {
902889
<!-- END HEADER -->
903890
<?php } // if $ALLOW_USER_HEADER ?>
904891

892+
<!-- BEGIN MCP -->
893+
<div class="tab-pane container fade" id="mcp"><div class="form-group">
894+
<fieldset class="border p-2">
895+
<legend><?php etranslate ('MCP Server')?></legend>
896+
<table style="border-collapse: separate; border-spacing: 1px; padding: 2px;">
897+
<tr><td data-toggle="tooltip" data-placement="top" title="<?php etooltip ("mcp-api-token-help");?>">
898+
<label for="mcp_api_token"><?php etranslate ( 'MCP API Token' )?>:</label></td><td class="form-inline mt-1">
899+
<?php if ( ! empty ( $mcp_new_token ) ) { ?>
900+
<input class="form-control" type="text" id="mcp_api_token_display" size="40" readonly value="<?php echo htmlspecialchars($mcp_new_token); ?>">
901+
<div class="text-warning mt-1"><?php etranslate('Copy this token now. For security it is stored hashed and cannot be shown again.'); ?></div>
902+
<?php } else { ?>
903+
<input class="form-control" type="text" id="mcp_api_token_display" size="40" readonly
904+
value="<?php echo $mcp_token_is_set ? '************************ (token set)' : ''; ?>">
905+
<?php } ?>
906+
<button type="button" class="btn btn-secondary ml-2" onclick="generateApiToken()"><?php etranslate('Generate New Token');?></button>
907+
<?php if ( $mcp_token_is_set || ! empty ( $mcp_new_token ) ) { ?>
908+
<button type="button" class="btn btn-outline-danger ml-2" onclick="clearApiToken()"><?php etranslate('Clear Token');?></button>
909+
<?php } ?>
910+
</td></tr>
911+
</table>
912+
<?php $mcp_endpoint = getServerUrl() . 'mcp.php'; ?>
913+
<div class="mt-2"><strong><?php etranslate('MCP Endpoint URL')?>:</strong>
914+
<code><?php echo htmlspecialchars($mcp_endpoint); ?></code></div>
915+
<div class="mt-2"><strong><?php etranslate('Sample agent configuration')?>:</strong>
916+
<div class="text-muted"><small><?php etranslate('Paste this into your AI agent MCP settings file (for example, mcp_settings.json).')?></small></div>
917+
<?php
918+
$mcp_sample_token = ! empty ( $mcp_new_token ) ? $mcp_new_token : 'YOUR_MCP_TOKEN';
919+
$mcp_sample = "{\n \"mcpServers\": {\n \"webcalendar\": {\n \"url\": \""
920+
. $mcp_endpoint . "\",\n \"headers\": {\n \"X-MCP-Token\": \""
921+
. $mcp_sample_token . "\"\n }\n }\n }\n}";
922+
?>
923+
<pre class="border rounded p-2 mt-1" style="white-space:pre-wrap;"><?php echo htmlspecialchars($mcp_sample); ?></pre>
924+
<?php if ( empty ( $mcp_new_token ) ) { ?>
925+
<div class="text-muted"><small><?php etranslate('Replace YOUR_MCP_TOKEN with a token generated above.')?></small></div>
926+
<?php } ?>
927+
</div>
928+
</fieldset>
929+
</div></div>
930+
<!-- END MCP -->
931+
905932
<!-- BEGIN COLORS -->
906933

907934
<?php if ( $ALLOW_COLOR_CUSTOMIZATION == 'Y' ) { ?>

0 commit comments

Comments
 (0)