Skip to content

Commit a63ae50

Browse files
committed
2 parents 14a44c8 + 71bfb94 commit a63ae50

6 files changed

Lines changed: 681 additions & 0 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ Now Cursor AI can understand your codebase! Try asking it questions like:
7676
- "List all .csproj files in this directory"
7777
- "Show me the contents of this file"
7878
- "What's the current base directory for file operations?"
79+
- "Help me think through the authentication system design"
80+
- "Document my reasoning about this architectural decision"
7981

8082
## 📚 Documentation
8183

@@ -93,6 +95,12 @@ Now Cursor AI can understand your codebase! Try asking it questions like:
9395
- 📖 **File Content Access**: Read source files with safety checks and size limits
9496
- 🛡️ **Security**: Built-in safeguards for sensitive files and directory access
9597
- 🎯 **Pattern Management**: Flexible ignore patterns for controlling file access
98+
- 💭 **Structured Thinking**: Document and validate reasoning about complex operations
99+
- 🧩 **AI-Optimized Reasoning**: Based on [Anthropic's research](https://www.anthropic.com/engineering/claude-think-tool) on improving LLM problem-solving
100+
- 📋 **Task Planning**: Break down complex problems into manageable steps
101+
-**Policy Compliance**: Verify solutions against project guidelines
102+
- 🔄 **Tool Output Analysis**: Process results from other tools before taking next actions
103+
- 📝 **Decision Documentation**: Maintain audit trails of architectural choices
96104

97105
## Building from Source
98106

docs/tool-reference.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,151 @@ Simple health check endpoint that returns a greeting message.
245245
dotnet run --project src/NetContextClient/NetContextClient.csproj -- hello
246246
```
247247

248+
### `think`
249+
Provides a space for structured thinking during complex operations, allowing AI models to reason about actions, verify compliance with rules, and plan next steps without making any state changes.
250+
251+
**Parameters:**
252+
- `--thought` (required): The thought or reasoning to process
253+
254+
**Example:**
255+
```bash
256+
dotnet run --project src/NetContextClient/NetContextClient.csproj -- think --thought "Planning to refactor the authentication module to use JWT tokens"
257+
```
258+
259+
**Output Example:**
260+
```json
261+
{
262+
"thought": "Planning to refactor the authentication module to use JWT tokens",
263+
"message": "Thought processed successfully",
264+
"category": "Refactoring",
265+
"timestamp": "2024-03-21T14:30:00.000Z",
266+
"characterCount": 58
267+
}
268+
```
269+
270+
**When to Use:**
271+
The think tool is particularly valuable when you want Claude to:
272+
1. Break down complex problems into manageable steps
273+
2. Analyze tool outputs before taking further actions
274+
3. Verify compliance with project policies and rules
275+
4. Plan multi-step operations that require careful consideration
276+
5. Document reasoning about architectural decisions
277+
278+
> 📚 **Learn More**: This implementation is based on Anthropic's research on improving Claude's performance with a dedicated thinking space. [Read their detailed blog post](https://www.anthropic.com/engineering/claude-think-tool) for more insights.
279+
280+
**Best Practice Examples:**
281+
282+
1. **Multi-step Task Planning**
283+
```
284+
Before implementing a new feature, use the think tool to:
285+
- List all required functionality
286+
- Identify affected components and files
287+
- Plan the implementation sequence
288+
- Consider potential edge cases
289+
- Outline test scenarios
290+
291+
Example: When adding authentication, think through: user flow, security requirements, error states, and affected API endpoints.
292+
```
293+
294+
2. **Policy Compliance Verification**
295+
```
296+
When evaluating solutions against project guidelines, use the think tool to:
297+
- List all relevant policies
298+
- Check each policy requirement against the solution
299+
- Identify any compliance gaps
300+
- Document justifications for approach
301+
- Flag areas needing further review
302+
303+
Example: "Before implementing this database change, let me verify it meets our data security policies..."
304+
```
305+
306+
3. **Tool Output Analysis**
307+
```
308+
After receiving complex tool outputs (like search results or code analysis), use the think tool to:
309+
- Summarize key findings
310+
- Identify patterns across results
311+
- Connect information from different sources
312+
- Determine next investigation steps
313+
- Validate assumptions based on collected data
314+
315+
Example: "After searching the codebase for auth-related files, I've found these patterns..."
316+
```
317+
318+
4. **Architectural Decision Documentation**
319+
```
320+
When making architectural choices, use the think tool to:
321+
- Document decision criteria
322+
- Compare alternative approaches
323+
- List pros and cons of each option
324+
- Justify the chosen solution
325+
- Note implications for future development
326+
327+
Example: "Considering three approaches for the caching layer: in-memory, Redis, or database..."
328+
```
329+
330+
**Features:**
331+
- Automatic thought categorization:
332+
- Refactoring: Code restructuring and improvements
333+
- Security: Security-related considerations
334+
- Performance: Optimization and performance improvements
335+
- Testing: Testing and debugging thoughts
336+
- Architecture: Design and architectural decisions
337+
- General: Other uncategorized thoughts
338+
- Detailed metadata including timestamps and character counts
339+
- Content validation for potentially harmful patterns
340+
- Support for Unicode characters and emoji
341+
- Automatic log rotation for debugging logs
342+
343+
**Limitations and Considerations:**
344+
- The tool is stateless - it doesn't persist thoughts between invocations
345+
- No state changes are made to the codebase
346+
- Maximum thought length is 32KB (32,768 characters)
347+
- Potentially harmful content is automatically rejected
348+
- Timestamps are in ISO 8601 format (UTC)
349+
- Log files are automatically rotated at 5MB
350+
351+
**Logging Configuration:**
352+
Enable thought logging by setting the environment variable:
353+
```bash
354+
# PowerShell
355+
$env:NETCONTEXT_LOG_THOUGHTS="true"
356+
357+
# Bash
358+
export NETCONTEXT_LOG_THOUGHTS="true"
359+
```
360+
361+
Logs are stored in:
362+
- Location: `[AppDirectory]/logs/thoughts.log`
363+
- Format: `[Timestamp] JSON-formatted-thought-data`
364+
- Rotation: Automatic at 5MB with timestamp-based archiving
365+
366+
**Integration with AI Workflows:**
367+
When working with Claude, the think tool can be used to:
368+
- Document decision-making processes
369+
- Create structured plans for complex refactoring
370+
- Validate approaches against project guidelines
371+
- Break down large tasks into smaller, manageable steps
372+
- Maintain a clear record of reasoning in the conversation history
373+
- Track thought patterns through categorization
374+
375+
**Error Handling:**
376+
The tool returns error responses in the following cases:
377+
```json
378+
{
379+
"error": "Missing required parameter 'thought'"
380+
}
381+
```
382+
```json
383+
{
384+
"error": "Error: Thought exceeds maximum length of 32768 characters"
385+
}
386+
```
387+
```json
388+
{
389+
"error": "Error: Thought contains invalid content"
390+
}
391+
```
392+
248393
## Default Ignore Patterns
249394

250395
The following patterns are ignored by default to protect sensitive information:
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace NetContextClient.Models;
2+
3+
/// <summary>
4+
/// Response model for the think tool.
5+
/// </summary>
6+
public class ThinkResponse
7+
{
8+
/// <summary>
9+
/// The thought that was processed.
10+
/// </summary>
11+
public string Thought { get; set; } = string.Empty;
12+
13+
/// <summary>
14+
/// A confirmation message about the thought processing.
15+
/// </summary>
16+
public string Message { get; set; } = string.Empty;
17+
18+
/// <summary>
19+
/// Error message if something went wrong.
20+
/// </summary>
21+
public string? Error { get; set; }
22+
}

src/NetContextClient/Program.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
using ModelContextProtocol.Protocol.Transport;
44
using NetContextClient.Models;
55
using System.CommandLine;
6+
using System.Text.Encodings.Web;
67
using System.Text.Json;
8+
using System.Text.Json.Serialization;
9+
using System.Text.Unicode;
710

811
/// <summary>
912
/// Command-line interface for the .NET Context Client, which interacts with the MCP server
@@ -18,6 +21,21 @@
1821
/// </summary>
1922
class Program
2023
{
24+
/// <summary>
25+
/// Default JSON serializer options used for response deserialization.
26+
/// </summary>
27+
private static readonly JsonSerializerOptions DefaultJsonOptions = new()
28+
{
29+
WriteIndented = true,
30+
PropertyNameCaseInsensitive = true,
31+
AllowTrailingCommas = true,
32+
ReadCommentHandling = JsonCommentHandling.Skip,
33+
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
34+
DictionaryKeyPolicy = JsonNamingPolicy.CamelCase,
35+
DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull,
36+
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
37+
};
38+
2139
/// <summary>
2240
/// Entry point for the command-line interface. Sets up the MCP client and defines
2341
/// the command structure using System.CommandLine.
@@ -703,6 +721,38 @@ static async Task<int> Main(string[] args)
703721
}
704722
});
705723

724+
// Think command
725+
var thinkCommand = new Command("think", "Process a thought without making any state changes");
726+
var thoughtOption = new Option<string>("--thought", "The thought to process") { IsRequired = true };
727+
thinkCommand.AddOption(thoughtOption);
728+
thinkCommand.SetHandler(async (string thought) =>
729+
{
730+
try
731+
{
732+
var result = await client.CallToolAsync("think", new() { ["thought"] = thought });
733+
var jsonText = result.Content.First(c => c.Type == "text").Text;
734+
if (jsonText != null)
735+
{
736+
var response = JsonSerializer.Deserialize<ThinkResponse>(jsonText, DefaultJsonOptions);
737+
738+
if (!string.IsNullOrEmpty(response?.Error))
739+
{
740+
await Console.Error.WriteLineAsync($"Error: {response.Error}");
741+
return;
742+
}
743+
744+
await Console.Out.WriteLineAsync("Processed thought:");
745+
await Console.Out.WriteLineAsync($" {response?.Thought}");
746+
await Console.Out.WriteLineAsync($"\n{response?.Message}");
747+
}
748+
}
749+
catch (Exception ex)
750+
{
751+
await Console.Error.WriteLineAsync($"Error: {ex.Message}");
752+
Environment.Exit(1);
753+
}
754+
}, thoughtOption);
755+
706756
rootCommand.AddCommand(helloCommand);
707757
rootCommand.AddCommand(setBaseDirCommand);
708758
rootCommand.AddCommand(getBaseDirCommand);
@@ -720,6 +770,7 @@ static async Task<int> Main(string[] args)
720770
rootCommand.AddCommand(getStateFileLocationCommand);
721771
rootCommand.AddCommand(semanticSearchCommand);
722772
rootCommand.AddCommand(analyzePackagesCommand);
773+
rootCommand.AddCommand(thinkCommand);
723774

724775
return await rootCommand.InvokeAsync(args);
725776
}

0 commit comments

Comments
 (0)